





from ..utils import DummyObject, requires_backends





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:List[str]    ,   *_UpperCamelCase	:int    ,   **_UpperCamelCase	:Dict )->					List[str]:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:int    ,   *_UpperCamelCase	:Union[str, Any]    ,   **_UpperCamelCase	:Tuple )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Any    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:Any )->					Optional[int]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:List[str]    ,   *_UpperCamelCase	:Dict    ,   **_UpperCamelCase	:Tuple )->					int:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:int    ,   *_UpperCamelCase	:List[Any]    ,   **_UpperCamelCase	:Union[str, Any] )->					str:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Optional[Any]    ,   *_UpperCamelCase	:Tuple    ,   **_UpperCamelCase	:int )->					int:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:int    ,   *_UpperCamelCase	:Tuple    ,   **_UpperCamelCase	:Dict )->					int:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Any    ,   *_UpperCamelCase	:str    ,   **_UpperCamelCase	:Optional[Any] )->					int:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Any    ,   *_UpperCamelCase	:Tuple    ,   **_UpperCamelCase	:str )->					List[Any]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[int]    ,   *_UpperCamelCase	:Union[str, Any]    ,   **_UpperCamelCase	:Any )->					int:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Union[str, Any]    ,   *_UpperCamelCase	:List[str]    ,   **_UpperCamelCase	:Union[str, Any] )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Tuple    ,   *_UpperCamelCase	:List[Any]    ,   **_UpperCamelCase	:Optional[Any] )->					str:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[Any]    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:Dict )->					Optional[int]:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Tuple    ,   *_UpperCamelCase	:Dict    ,   **_UpperCamelCase	:Tuple )->					Optional[Any]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:int    ,   *_UpperCamelCase	:Any    ,   **_UpperCamelCase	:List[Any] )->					Union[str, Any]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[Any]    ,   *_UpperCamelCase	:Dict    ,   **_UpperCamelCase	:Union[str, Any] )->					Dict:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Optional[int]    ,   *_UpperCamelCase	:Optional[Any]    ,   **_UpperCamelCase	:Any )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:str    ,   *_UpperCamelCase	:str    ,   **_UpperCamelCase	:Union[str, Any] )->					str:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:str    ,   *_UpperCamelCase	:Any    ,   **_UpperCamelCase	:int )->					List[Any]:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Any    ,   *_UpperCamelCase	:List[Any]    ,   **_UpperCamelCase	:Union[str, Any] )->					int:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:List[Any]    ,   *_UpperCamelCase	:Tuple    ,   **_UpperCamelCase	:Dict )->					int:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:int    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:Optional[Any] )->					Optional[int]:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:int    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:Optional[int] )->					Optional[int]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Tuple    ,   *_UpperCamelCase	:int    ,   **_UpperCamelCase	:Optional[Any] )->					str:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[int]    ,   *_UpperCamelCase	:int    ,   **_UpperCamelCase	:int )->					int:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Dict    ,   *_UpperCamelCase	:Dict    ,   **_UpperCamelCase	:Tuple )->					Dict:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Dict    ,   *_UpperCamelCase	:Any    ,   **_UpperCamelCase	:Optional[int] )->					Optional[int]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[int]    ,   *_UpperCamelCase	:Any    ,   **_UpperCamelCase	:List[Any] )->					Tuple:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Optional[Any]    ,   *_UpperCamelCase	:Union[str, Any]    ,   **_UpperCamelCase	:Tuple )->					Optional[Any]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Optional[Any]    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:Union[str, Any] )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[int]    ,   *_UpperCamelCase	:Optional[Any]    ,   **_UpperCamelCase	:str )->					Any:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Optional[Any]    ,   *_UpperCamelCase	:Any    ,   **_UpperCamelCase	:Union[str, Any] )->					List[Any]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Tuple    ,   *_UpperCamelCase	:Union[str, Any]    ,   **_UpperCamelCase	:Optional[Any] )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:int    ,   *_UpperCamelCase	:Optional[Any]    ,   **_UpperCamelCase	:List[Any] )->					Dict:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Dict    ,   *_UpperCamelCase	:str    ,   **_UpperCamelCase	:Optional[int] )->					str:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:Any    ,   *_UpperCamelCase	:Union[str, Any]    ,   **_UpperCamelCase	:Any )->					Union[str, Any]:
         requires_backends(cls    ,   ['''flax'''] )





class A_					(			metaclass=_lowerCamelCase   ):
   lowerCAmelCase__        = ["""flax"""]




   def __init__(self	:Optional[Any]    ,   *_UpperCamelCase	:str    ,   **_UpperCamelCase	:Optional[Any] )->					Optional[Any]:
         requires_backends(self    ,   ['''flax'''] )




   @classmethod
   def _lowerCAmelCase      (cls	:Dict    ,   *_UpperCamelCase	:Dict    ,   **_UpperCamelCase	:str )->					List[str]:
         requires_backends(cls    ,   ['''flax'''] )






   @classmethod
   def _lowerCAmelCase      (cls	:List[str]    ,   *_UpperCamelCase	:str    ,   **_UpperCamelCase	:Optional[int] )->					Tuple:
         requires_backends(cls    ,   ['''flax'''] )












from __future__ import annotations



def _a				(	lowerCamelCase:   list[float]					,				lowerCamelCase:   Tuple )	->						List[str]:







      '''simple docstring'''






      print(F"""Vertex\tShortest Distance from vertex {src}""" )
      for i, d in enumerate(lowerCamelCase ):
            print(F"""{i}\t\t{d}""" )



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   list[float]					,				lowerCamelCase:   int )	->						Union[str, Any]:







      '''simple docstring'''






      for j in range(lowerCamelCase ):
            __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])
            if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                  return True
      return False



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   int					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						list[float]:







      '''simple docstring'''






      __A          =				[float('''inf''' )] * vertex_count
      __A          =				0.0

      for _ in range(vertex_count - 1 ):
            for j in range(lowerCamelCase ):
                  __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])

                  if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                        __A          =				distance[u] + w

      __A          =				check_negative_cycle(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
      if negative_cycle_exists:
            raise Exception('''Negative cycle found''' )

      return distance


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       snake_case__					:							Dict													=     int(input('Enter number of vertices: ').strip())
       snake_case__					:							Optional[int]													=     int(input('Enter number of edges: ').strip())

       snake_case__					:							list[dict[str, int]]													=     [{} for _ in range(E)]

       for i in range(E):
              print('Edge ', i + 1)
              snake_case__						,    snake_case__						,    snake_case__					:							Dict													=     (
                  int(x)
                  for x in input('Enter source, destination, weight: ').strip().split(' ')
              )
              snake_case__					:							List[Any]													=     {'src': src, 'dst': dest, 'weight': weight}

       snake_case__					:							Union[str, Any]													=     int(input('\nEnter shortest path source:').strip())
       snake_case__					:							List[Any]													=     bellman_ford(graph, V, E, source)
       print_distance(shortest_distance, 0)





