
'''simple docstring'''



def A				(__lowerCamelCase				:Dict		):
						_lowerCAmelCase  						=			set()
						# To detect a back edge, keep track of vertices currently in the recursion stack
						_lowerCAmelCase  						=			set()
						return any(
						    node not in visited and depth_first_search(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase		)
						    for node in graph		)


def A				(__lowerCamelCase				:Dict			,     __lowerCamelCase				:int			,     __lowerCamelCase				:int			,     __lowerCamelCase				:Optional[int]		):
						visited.add(__lowerCamelCase		)
						rec_stk.add(__lowerCamelCase		)

						for node in graph[vertex]:
												if node not in visited:
																		if depth_first_search(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase		):
																								return True
												elif node in rec_stk:
																		return True

												# The node needs to be removed from recursion stack before function ends
						rec_stk.remove(__lowerCamelCase		)
						return False


if __name__ == "__main__":
						from doctest import testmod

						testmod()


'''simple docstring'''



from __future__ import annotations

from typing import Any




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						pass






class   UpperCAmelCase_					:






						'''simple docstring'''






						def __init__( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			data
												_lowerCAmelCase  						=			None




						def __iter__( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self
												_lowerCAmelCase  						=			[]
												while node:
																		if node in visited:
																								raise ContainsLoopError
																		visited.append(_lowercase				)
																		yield node.data
																		_lowerCAmelCase  						=			node.next_node




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												try:
																		list(self				)
																		return False
												except ContainsLoopError:
																		return True


if __name__ == "__main__":
						_lowercase    =		Node(1)
						_lowercase    =		Node(2)
						_lowercase    =		Node(3)
						_lowercase    =		Node(4)
						print(root_node.has_loop)  # False
						_lowercase    =		root_node.next_node
						print(root_node.has_loop)  # True

						_lowercase    =		Node(5)
						_lowercase    =		Node(6)
						_lowercase    =		Node(5)
						_lowercase    =		Node(6)
						print(root_node.has_loop)  # False

						_lowercase    =		Node(1)
						print(root_node.has_loop)  # False
