





class       __lowerCAmelCase					:


	'''simple docstring'''





	def __init__(						self:						Optional[Any]			):
			lowercase__					:      Optional[int]      =		{}

	def    snake_case__(						self:						Tuple			):
			print(self.vertex			)
			for i in self.vertex:
					print(lowerCamelCase_,					' -> ',					' -> '.join([str(lowerCamelCase_			) for j in self.vertex[i]]			)			)

	def    snake_case__(						self:						str,					lowerCamelCase_:						int,					lowerCamelCase_:						int			):
			# check if vertex is already present,
			if from_vertex in self.vertex:
					self.vertex[from_vertex].append(lowerCamelCase_			)
			else:
					# else make a new vertex
					lowercase__					:      Optional[Any]      =		[to_vertex]

	def    snake_case__(						self:						int			):
			# visited array for storing already visited nodes
			lowercase__					:      List[Any]      =		[False] * len(self.vertex			)

			# call the recursive helper function
			for i in range(len(self.vertex			)			):
					if not visited[i]:
							self.dfs_recursive(lowerCamelCase_,					lowerCamelCase_			)





	def    snake_case__(						self:						Any,					lowerCamelCase_:						int,					lowerCamelCase_:						list			):
			# mark start vertex as visited
			lowercase__					:      Any      =		True

			print(lowerCamelCase_,					end=' '			)

			# Recur for all the vertices that are adjacent to this node
			for i in self.vertex:
					if not visited[i]:
							self.dfs_recursive(lowerCamelCase_,					lowerCamelCase_			)


if __name__ == "__main__":
			__UpperCamelCase:	str = Graph()
			g.add_edge(0, 1)
			g.add_edge(0, 2)
			g.add_edge(1, 2)
			g.add_edge(2, 0)
			g.add_edge(2, 3)
			g.add_edge(3, 3)

			g.print_graph()
			print("""DFS:""")
			g.dfs()

			# OUTPUT:
			# 0  ->  1 -> 2
			# 1  ->  2
			# 2  ->  0 -> 3
			# 3  ->  3
			# DFS:
			#  0 1 2 3









__UpperCamelCase:	str = {0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

__UpperCamelCase:	Tuple = {0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]   ,    _lowercase     : int   ,    _lowercase     : list[bool]			)   ->							list[int]:




		'''simple docstring'''
		lowercase__					:      str      =		True
		lowercase__					:      int      =		[]

		for neighbour in graph[vert]:
				if not visited[neighbour]:
						order += topology_sort(_lowercase   ,    _lowercase   ,    _lowercase			)

		order.append(_lowercase			)

		return order


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]   ,    _lowercase     : int   ,    _lowercase     : list[bool]			)   ->							list[int]:




		'''simple docstring'''
		lowercase__					:      Union[str, Any]      =		True
		lowercase__					:      Optional[Any]      =		[vert]

		for neighbour in reversed_graph[vert]:
				if not visited[neighbour]:
						component += find_components(_lowercase   ,    _lowercase   ,    _lowercase			)

		return component





def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]			)   ->							list[list[int]]:




		'''simple docstring'''
		lowercase__					:      Optional[int]      =		len(_lowercase			) * [False]
		lowercase__					:      dict[int, list[int]]      =		{vert: [] for vert in range(len(_lowercase			)			)}

		for vert, neighbours in graph.items():
				for neighbour in neighbours:
						reversed_graph[neighbour].append(_lowercase			)

		lowercase__					:      Dict      =		[]
		for i, was_visited in enumerate(_lowercase			):
				if not was_visited:
						order += topology_sort(_lowercase   ,    _lowercase   ,    _lowercase			)

		lowercase__					:      Dict      =		[]
		lowercase__					:      Optional[Any]      =		len(_lowercase			) * [False]

		for i in range(len(_lowercase			)			):
				lowercase__					:      List[Any]      =		order[len(_lowercase			) - i - 1]
				if not visited[vert]:
						lowercase__					:      Tuple      =		find_components(_lowercase   ,    _lowercase   ,    _lowercase			)
						components_list.append(_lowercase			)

		return components_list


