


from __future__ import annotations

from queue import Queue




class A						:






      def __init__(      self		:  Optional[int]				)      ->		None:
             """simple docstring"""




             _lowerCamelCase :	dict[int, list[int]]						={}






      def  lowerCamelCase (      self		:  int				)      ->		None:
             """simple docstring"""




             for i in self.vertices:
                    print(lowercase_    ,     ' : '    ,     ' -> '.join([str(lowercase_				) for j in self.vertices[i]]				)				)






      def  lowerCamelCase (      self		:  str    ,     lowercase_		:  int    ,     lowercase_		:  int				)      ->		None:
             """simple docstring"""




             if from_vertex in self.vertices:
                    self.vertices[from_vertex].append(lowercase_				)
             else:
                    _lowerCamelCase :	int						=[to_vertex]






      def  lowerCamelCase (      self		:  int    ,     lowercase_		:  int				)      ->		set[int]:
             """simple docstring"""




             _lowerCamelCase :	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(lowercase_				)
             queue.put(lowercase_				)

             while not queue.empty():
                    _lowerCamelCase :	Optional[int]						=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(lowercase_				)
                                  visited.add(lowercase_				)
             return visited


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

 testmod(verbose=True)

 lowerCamelCase		      = 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 collections.abc import Callable

lowerCamelCase		      = Callable[[float], float]  # type alias for a real -> real function




def 			a_   (					SCREAMING_SNAKE_CASE__      :   RealFunc	,    SCREAMING_SNAKE_CASE__      :   RealFunc	,    SCREAMING_SNAKE_CASE__      :   int	,    ):
       '''simple docstring'''





       _lowerCamelCase :	Tuple						=float(SCREAMING_SNAKE_CASE__  )
       while True:
              try:
                     _lowerCamelCase :	int						=prev_guess - function(SCREAMING_SNAKE_CASE__  ) / derivative(SCREAMING_SNAKE_CASE__  )
              except ZeroDivisionError:
                     raise ZeroDivisionError('Could not find root'  ) from None
              if abs(prev_guess - next_guess  ) < 10**-5:
                     return next_guess
              _lowerCamelCase :	Union[str, Any]						=next_guess




def 			a_   (					SCREAMING_SNAKE_CASE__      :   float  ):
       '''simple docstring'''





       return (x**3) - (2 * x) - 5




def 			a_   (					SCREAMING_SNAKE_CASE__      :   float  ):
       '''simple docstring'''





       return 3 * (x**2) - 2


if __name__ == "__main__":
 print(newton(f, fa, 3))


