


from __future__ import annotations

from queue import Queue





class    lowerCAmelCase__				:






						"""simple docstring"""




						def __init__(   self     ):
							lowerCamelCase_			:							dict[int, list[int]]      =       {}




						def 					_UpperCamelCase			(   self     ):
							for i in self.vertices:
								print(a_				,							" : "				,							" -> ".join([str(a_     ) for j in self.vertices[i]]     )     )




						def 					_UpperCamelCase			(   self				,							a_				,							a_     ):
							if from_vertex in self.vertices:
								self.vertices[from_vertex].append(a_     )
							else:
								lowerCamelCase_			:							Any      =       [to_vertex]




						def 					_UpperCamelCase			(   self				,							a_     ):
							lowerCamelCase_			:							List[str]      =       set()

							# create a first in first out queue to store all the vertices for BFS
							lowerCamelCase_			:							Queue      =       Queue()

							# mark the source node as visited and enqueue it
							visited.add(a_     )
							queue.put(a_     )

							while not queue.empty():
								lowerCamelCase_			:							str      =       queue.get()

								# loop through all adjacent vertex and enqueue it if not yet visited
								for adjacent_vertex in self.vertices[vertex]:
									if adjacent_vertex not in visited:
										queue.put(a_     )
										visited.add(a_     )
							return visited


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

							testmod(verbose=True)

							__magic_name__       					=      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()
							# 0  :  1 -> 2
							# 1  :  2
							# 2  :  0 -> 3
							# 3  :  3

							assert sorted(g.bfs(2)) == [0, 1, 2, 3]





from __future__ import annotations





class    lowerCAmelCase__				:






						"""simple docstring"""




						def __init__(   self				,							a_     ):
							lowerCamelCase_			:							List[str]      =       value
							lowerCamelCase_			:							Node | None      =       None
							lowerCamelCase_			:							Node | None      =       None





class    lowerCAmelCase__				:






						"""simple docstring"""
						__UpperCAmelCase   :		int




						def __init__(   self     ):
							lowerCamelCase_			:							str      =       0




						def 					_UpperCamelCase			(   self				,							a_				,							a_     ):
							if node is None:
								return

							if path_sum == self.target:
								self.paths += 1

							if node.left:
								self.depth_first_search(node.left				,							path_sum + node.left.value     )
							if node.right:
								self.depth_first_search(node.right				,							path_sum + node.right.value     )




						def 					_UpperCamelCase			(   self				,							a_				,							a_ = None     ):
							if node is None:
								return 0
							if target is not None:
								lowerCamelCase_			:							List[str]      =       target

							self.depth_first_search(a_				,							node.value     )
							self.path_sum(node.left     )
							self.path_sum(node.right     )

							return self.paths


if __name__ == "__main__":
							import doctest

							doctest.testmod()

