




from __future__ import annotations



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



def       UpperCAmelCase__  (     lowerCamelCase,			lowerCamelCase,			lowerCamelCase   ):
  for j in range(_UpperCAmelCase   ):
    lowercase	,    lowercase	,    lowercase    :List[Any]      	=						(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       UpperCAmelCase__  (     lowerCamelCase,			lowerCamelCase,			lowerCamelCase,			lowerCamelCase   ):
  lowercase    :Optional[Any]      	=						[float("inf"   )] * vertex_count
  lowercase    :Any      	=						0.0

  for _ in range(vertex_count - 1   ):
    for j in range(_UpperCAmelCase   ):
      lowercase	,    lowercase	,    lowercase    :Optional[Any]      	=						(graph[j][k] for k in ["src", "dst", "weight"])

      if distance[u] != float("inf"   ) and distance[u] + w < distance[v]:
        lowercase    :int      	=						distance[u] + w

  lowercase    :Tuple      	=						check_negative_cycle(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase   )
  if negative_cycle_exists:
    raise Exception("Negative cycle found"   )

  return distance


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     _UpperCAmelCase	:						Dict			=     int(input("Enter number of vertices: ").strip())
     _UpperCAmelCase	:						Any			=     int(input("Enter number of edges: ").strip())

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

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

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






import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment




@require_huggingface_suite
class    __lowerCAmelCase       (							unittest.TestCase):






       def 					SCREAMING_SNAKE_CASE    (   self:					List[str]				):
         lowercase    :List[str]      	=						inspect.getfile(accelerate.test_utils				)
         lowercase    :List[Any]      	=						os.path.sep.join(
             mod_file.split(os.path.sep				)[:-1] + ["scripts", "external_deps", "test_metrics.py"]				)

         from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

         lowercase    :str      	=						test_metrics






       @require_cpu
       def 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):
         debug_launcher(self.test_metrics.main       ,					num_processes=1				)






       @require_cpu
       def 					SCREAMING_SNAKE_CASE    (   self:					int				):
         debug_launcher(self.test_metrics.main				)






       @require_single_gpu
       def 					SCREAMING_SNAKE_CASE    (   self:					List[Any]				):
         self.test_metrics.main()






       @require_multi_gpu
       def 					SCREAMING_SNAKE_CASE    (   self:					Optional[Any]				):
         print(F"Found {torch.cuda.device_count()} devices."				)
         lowercase    :str      	=						["torchrun", F"--nproc_per_node={torch.cuda.device_count()}", self.test_file_path]
         with patch_environment(omp_num_threads=1				):
           execute_subprocess_async(_lowerCAmelCase       ,					env=os.environ.copy()				)



