





import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp





def 					lowerCAmelCase_			(	)					->		Union[str, Any]:







  """simple docstring"""





  lowerCamelCase__:				Optional[int]        =ArgumentParser(
      description=(
          "PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"
      )		)

  # Optional arguments for the launch helper
  parser.add_argument("--num_cores"     ,   type=__a     ,   default=1     ,   help="Number of TPU cores to use (1 or 8)."		)

  # positional
  parser.add_argument(
      "training_script"     ,   type=__a     ,   help=(
          "The full path to the single TPU training "
          "program/script to be launched in parallel, "
          "followed by all the arguments for the "
          "training script"
      )     ,   )

  # rest from the training program
  parser.add_argument("training_script_args"     ,   nargs=__a		)

  return parser.parse_args()





def 					lowerCAmelCase_			(	)					->		Optional[Any]:







  """simple docstring"""





  lowerCamelCase__:				Union[str, Any]        =parse_args()

  # Import training_script as a module.
  lowerCamelCase__:				Dict        =Path(args.training_script		)
  sys.path.append(str(script_fpath.parent.resolve()		)		)
  lowerCamelCase__:				Optional[Any]        =script_fpath.stem
  lowerCamelCase__:				Dict        =importlib.import_module(__a		)

  # Patch sys.argv
  lowerCamelCase__:				int        =[args.training_script] + args.training_script_args + ["--tpu_num_cores", str(args.num_cores		)]

  xmp.spawn(mod._mp_fn     ,   args=()     ,   nprocs=args.num_cores		)


if __name__ == "__main__":
     main()








from __future__ import annotations





def 					lowerCAmelCase_			(	__a     ,   __a		)					->		List[Any]:







  """simple docstring"""





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





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a		)					->		Tuple:







  """simple docstring"""





  for j in range(__a		):
    lowerCamelCase__  , lowerCamelCase__  , lowerCamelCase__:				str        =(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 					lowerCAmelCase_			(	__a     ,   __a     ,   __a     ,   __a		)					->		list[float]:







  """simple docstring"""





  lowerCamelCase__:				List[str]        =[float("inf"		)] * vertex_count
  lowerCamelCase__:				List[str]        =0.0

  for _ in range(vertex_count - 1		):
    for j in range(__a		):
      lowerCamelCase__  , lowerCamelCase__  , lowerCamelCase__:				Union[str, Any]        =(graph[j][k] for k in ["src", "dst", "weight"])

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

  lowerCamelCase__:				Tuple        =check_negative_cycle(__a     ,   __a     ,   __a		)
  if negative_cycle_exists:
    raise Exception("Negative cycle found"		)

  return distance


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     __A     =    int(input("Enter number of vertices: ").strip())
     __A     =    int(input("Enter number of edges: ").strip())

     __A     =    [{} for _ in range(E)]

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

     __A     =    int(input("\nEnter shortest path source:").strip())
     __A     =    bellman_ford(graph, V, E, source)
     print_distance(shortest_distance, 0)

