






'''simple docstring'''

from collections import deque






def 						_UpperCAmelCase     (	a		:						str				)      ->      str:





						"""simple docstring"""
						return input(a				).strip().split(' '				)






def 						_UpperCAmelCase     (	a		:						int    ,      a		:						int				)      ->      dict[int, list[int]]:





						"""simple docstring"""
						lowercase_   : dict[int, list[int]]   	=      {}
						for i in range(a				):
												lowercase_   : str   	=      []

						for e in range(a				):
												lowercase_	,   lowercase_   : Optional[int]   	=      (int(a				) for i in _input(f"Edge {e + 1}: <node1> <node2> "				))
												graph[x].append(a				)
						return graph






def 						_UpperCAmelCase     (	a		:						int    ,      a		:						int				)      ->      dict[int, list[int]]:





						"""simple docstring"""
						lowercase_   : dict[int, list[int]]   	=      {}
						for i in range(a				):
												lowercase_   : str   	=      []

						for e in range(a				):
												lowercase_	,   lowercase_   : List[str]   	=      (int(a				) for i in _input(f"Edge {e + 1}: <node1> <node2> "				))
												graph[x].append(a				)
												graph[y].append(a				)
						return graph






def 						_UpperCAmelCase     (	a		:						int    ,      a		:						int				)      ->      dict[int, list[tuple[int, int]]]:





						"""simple docstring"""
						lowercase_   : dict[int, list[tuple[int, int]]]   	=      {}
						for i in range(a				):
												lowercase_   : List[Any]   	=      []

						for e in range(a				):
												lowercase_	,   lowercase_	,   lowercase_   : Tuple   	=      (int(a				) for i in _input(f"Edge {e + 1}: <node1> <node2> <weight> "				))
												graph[x].append((y, w)				)
												graph[y].append((x, w)				)
						return graph


if __name__ == "__main__":
						A					,		A:   int						=					(int(i) for i in _input("Number of nodes and edges: "))

						A:   List[str]						=					int(
						    _input(
						        "Press 1 or 2 or 3 \n"
						        "1. Unweighted directed \n"
						        "2. Unweighted undirected \n"
						        "3. Weighted undirected \n"
						    )[0]
						)

						A:   List[str]						=					{
						    1: initialize_unweighted_directed_graph,
						    2: initialize_unweighted_undirected_graph,
						    3: initialize_weighted_undirected_graph,
						}[graph_choice](n, m)






def 						_UpperCAmelCase     (	a		:						Dict    ,      a		:						int				)      ->      Any:





						"""simple docstring"""
						lowercase_	,   lowercase_   : Tuple   	=      {s}, [s]
						print(a				)
						while _s:
												lowercase_   : Union[str, Any]   	=      0
												for i in g[_s[-1]]:
																		if i not in vis:
																								_s.append(a				)
																								vis.add(a				)
																								lowercase_   : str   	=      1
																								print(a				)
																								break
												if not flag:
																		_s.pop()






def 						_UpperCAmelCase     (	a		:						Optional[Any]    ,      a		:						int				)      ->      int:





						"""simple docstring"""
						lowercase_	,   lowercase_   : List[str]   	=      {s}, deque([s]				)
						print(a				)
						while q:
												lowercase_   : Any   	=      q.popleft()
												for v in g[u]:
																		if v not in vis:
																								vis.add(a				)
																								q.append(a				)
																								print(a				)






def 						_UpperCAmelCase     (	a		:						List[Any]    ,      a		:						Any				)      ->      int:





						"""simple docstring"""
						lowercase_	,   lowercase_	,   lowercase_   : Tuple   	=      {s: 0}, set(), {s: 0}
						while True:
												if len(a				) == len(a				) - 1:
																		break
												lowercase_   : List[Any]   	=      1_0_0_0_0_0
												for i in dist:
																		if i not in known and dist[i] < mini:
																								lowercase_   : Union[str, Any]   	=      dist[i]
																								lowercase_   : Optional[int]   	=      i
												known.add(a				)
												for v in g[u]:
																		if v[0] not in known and dist[u] + v[1] < dist.get(v[0]    ,      1_0_0_0_0_0				):
																								lowercase_   : int   	=      dist[u] + v[1]
																								lowercase_   : List[Any]   	=      u
						for i in dist:
												if i != s:
																		print(dist[i]				)






def 						_UpperCAmelCase     (	a		:						Any    ,      a		:						Union[str, Any]=None    ,      a		:						Tuple=None				)      ->      str:





						"""simple docstring"""
						if q is None:
												lowercase_   : Tuple   	=      [1]
						if ind is None:
												lowercase_   : int   	=      [0] * (len(a				) + 1)  # SInce oth Index is ignored
												for u in g:
																		for v in g[u]:
																								ind[v] += 1
												lowercase_   : Optional[Any]   	=      deque()
												for i in g:
																		if ind[i] == 0:
																								q.append(a				)
						if len(a				) == 0:
												return
						lowercase_   : Optional[Any]   	=      q.popleft()
						print(a				)
						for w in g[v]:
												ind[w] -= 1
												if ind[w] == 0:
																		q.append(a				)
						topo(a    ,      a    ,      a				)






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





						"""simple docstring"""
						lowercase_   : Tuple   	=      input().strip()
						lowercase_   : str   	=      []
						for _ in range(a				):
												a.append(map(a    ,      input().strip().split()				)				)
						return a, n






def 						_UpperCAmelCase     (	a		:						Optional[Any]				)      ->      Dict:





						"""simple docstring"""
						((lowercase_)	,   (lowercase_))   : str   	=      a_and_n
						lowercase_   : Dict   	=      list(a				)
						lowercase_   : Any   	=      [[0] * n for i in range(a				)]
						for k in range(a				):
												for i in range(a				):
																		for j in range(a				):
																								if dist[i][j] > dist[i][k] + dist[k][j]:
																														lowercase_   : Tuple   	=      dist[i][k] + dist[k][j]
																														lowercase_   : Tuple   	=      k
						print(a				)






def 						_UpperCAmelCase     (	a		:						Optional[int]    ,      a		:						Any				)      ->      Optional[Any]:





						"""simple docstring"""
						lowercase_	,   lowercase_	,   lowercase_   : int   	=      {s: 0}, set(), {s: 0}
						while True:
												if len(a				) == len(a				) - 1:
																		break
												lowercase_   : Dict   	=      1_0_0_0_0_0
												for i in dist:
																		if i not in known and dist[i] < mini:
																								lowercase_   : Dict   	=      dist[i]
																								lowercase_   : Dict   	=      i
												known.add(a				)
												for v in g[u]:
																		if v[0] not in known and v[1] < dist.get(v[0]    ,      1_0_0_0_0_0				):
																								lowercase_   : Dict   	=      v[1]
																								lowercase_   : Optional[Any]   	=      u
						return dist






def 						_UpperCAmelCase     (	)      ->      Any:





						"""simple docstring"""
						lowercase_	,   lowercase_   : str   	=      map(a    ,      input().split(' '				)				)
						lowercase_   : Optional[int]   	=      []
						for _ in range(a				):
												edges.append(map(a    ,      input().split(' '				)				)				)
						return edges, n






def 						_UpperCAmelCase     (	a		:						str				)      ->      List[str]:





						"""simple docstring"""
						# Sort edges on the basis of distance
						((lowercase_)	,   (lowercase_))   : Optional[int]   	=      e_and_n
						e.sort(reverse=a    ,      key=lambda a				: x[2]				)
						lowercase_   : Optional[int]   	=      [{i} for i in range(1    ,      n + 1				)]
						while True:
												if len(a				) == 1:
																		break
												print(a				)
												lowercase_   : Dict   	=      e.pop()
												for i in range(len(a				)				):
																		if x[0] in s[i]:
																								break
												for j in range(len(a				)				):
																		if x[1] in s[j]:
																								if i == j:
																														break
																								s[j].update(s[i]				)
																								s.pop(a				)
																								break






def 						_UpperCAmelCase     (	a		:						Tuple				)      ->      Union[str, Any]:





						"""simple docstring"""
						lowercase_   : List[Any]   	=      []
						for node in graph:
												if not graph[node]:
																		isolated.append(a				)
						return isolated








'''simple docstring'''

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

import torch_xla.distributed.xla_multiprocessing as xmp






def 						_UpperCAmelCase     (	)      ->      Optional[Any]:





						"""simple docstring"""
						lowercase_   : List[str]   	=      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 						_UpperCAmelCase     (	)      ->      str:





						"""simple docstring"""
						lowercase_   : Optional[int]   	=      parse_args()

						# Import training_script as a module.
						lowercase_   : str   	=      Path(args.training_script				)
						sys.path.append(str(script_fpath.parent.resolve()				)				)
						lowercase_   : int   	=      script_fpath.stem
						lowercase_   : List[Any]   	=      importlib.import_module(a				)

						# Patch sys.argv
						lowercase_   : List[str]   	=      [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()
