





from __future__ import annotations







def 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    Any:
  print(F'''Vertex\tShortest Distance from vertex {src}''')
  for i, d in enumerate(__SCREAMING_SNAKE_CASE):
    print(F'''{i}\t\t{d}''')







def 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    List[Any]:
  for j in range(__SCREAMING_SNAKE_CASE):
    __snake_case  ,   __snake_case  ,   __snake_case:						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 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    List[Any]:
  __snake_case:						List[str]   =						[float("""inf""")] * vertex_count
  __snake_case:						Tuple   =						0.0

  for _ in range(vertex_count - 1):
    for j in range(__SCREAMING_SNAKE_CASE):
      __snake_case  ,   __snake_case  ,   __snake_case:						Optional[int]   =						(graph[j][k] for k in ["""src""", """dst""", """weight"""])

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

  __snake_case:						Optional[Any]   =						check_negative_cycle(__SCREAMING_SNAKE_CASE					,					__SCREAMING_SNAKE_CASE					,					__SCREAMING_SNAKE_CASE)
  if negative_cycle_exists:
    raise Exception("""Negative cycle found""")

  return distance


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      __UpperCAmelCase       :   int				       =							int(input("Enter number of vertices: ").strip())
      __UpperCAmelCase       :   Optional[Any]				       =							int(input("Enter number of edges: ").strip())

      __UpperCAmelCase       :   Dict				       =							[{} for _ in range(E)]

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

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








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

import torch_xla.distributed.xla_multiprocessing as xmp






def 							UpperCAmelCase_		(							):
	lowercase       =    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=__SCREAMING_SNAKE_CASE ,							default=1 ,							help='Number of TPU cores to use (1 or 8).'							)

	# positional
	parser.add_argument(
	    'training_script' ,							type=__SCREAMING_SNAKE_CASE ,							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=__SCREAMING_SNAKE_CASE							)

	return parser.parse_args()






def 							UpperCAmelCase_		(							):
	lowercase       =    parse_args()

	# Import training_script as a module.
	lowercase       =    Path(args.training_script							)
	sys.path.append(str(script_fpath.parent.resolve()							)							)
	lowercase       =    script_fpath.stem
	lowercase       =    importlib.import_module(__SCREAMING_SNAKE_CASE							)

	# Patch sys.argv
	lowercase       =    [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()

