






"""simple docstring"""





def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       print("\nVertex Distance"						)
       for i in range(snake_case_						):
              if dist[i] != float("inf"						):
                     print(snake_case_		,  "\t"		,  int(dist[i]						)		,  end="\t"						)
              else:
                     print(snake_case_		,  "\t"		,  "INF"		,  end="\t"						)
              print()






def 							A(    snake_case_		,  snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							List[str]         =     float("inf"						)
       lowercase__:							Any         =     -1
       for i in range(snake_case_						):
              if (not vset[i]) and mdist[i] < min_val:
                     lowercase__:							List[Any]         =     i
                     lowercase__:							int         =     mdist[i]
       return min_ind






def 							A(    snake_case_		,  snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							Dict         =     [float("inf"						) for _ in range(snake_case_						)]
       lowercase__:							Tuple         =     [False for _ in range(snake_case_						)]
       lowercase__:							Union[str, Any]         =     0.0

       for _ in range(v - 1						):
              lowercase__:							Tuple         =     min_dist(snake_case_		,  snake_case_		,  snake_case_						)
              lowercase__:							int         =     True

              for i in range(snake_case_						):
                     if (
                         (not vset[i])
                         and graph[u][i] != float("inf"						)
                         and mdist[u] + graph[u][i] < mdist[i]
                     ):
                            lowercase__:							Optional[int]         =     mdist[u] + graph[u][i]

       print_dist(snake_case_		,  snake_case_						)


if __name__ == "__main__":
  UpperCamelCase					=     int(input("""Enter number of vertices: """).strip())
  UpperCamelCase					=     int(input("""Enter number of edges: """).strip())

  UpperCamelCase					=     [[float("""inf""") for i in range(V)] for j in range(V)]

  for i in range(V):
    UpperCamelCase					=     0.0

  for i in range(E):
    print("""\nEdge """, i + 1)
    UpperCamelCase					=     int(input("""Enter source:""").strip())
    UpperCamelCase					=     int(input("""Enter destination:""").strip())
    UpperCamelCase					=     float(input("""Enter weight:""").strip())
    UpperCamelCase					=     weight

  UpperCamelCase					=     int(input("""\nEnter shortest path source:""").strip())
  dijkstra(graph, V, gsrc)














import torch

from accelerate import Accelerator, DistributedType

class        snake_case_				:







   """simple docstring"""



   def __enter__(     self:						int						)	->		Tuple:


       """simple docstring"""



       if self.enabled:
           _lowercase     			=						self.model.no_sync()
           self.model_sync_obj.__enter__()

       return self

   def __exit__(     self:						str ,							snake_case__:						Tuple ,							snake_case__:						int ,							snake_case__:						Tuple						)	->		Any:


       """simple docstring"""



       if self.enabled:
           # Average all models on exit
           self._sync_and_avg_model_params()
           self.model_sync_obj.__exit__(snake_case__ ,							snake_case__ ,							snake_case__						)

   def __init__(     self:						int ,							snake_case__:						Accelerator ,							snake_case__:						torch.nn.Module ,							snake_case__:						int ,							snake_case__:						bool = True						)	->		Optional[Any]:


       """simple docstring"""



       if accelerator.distributed_type not in [
           DistributedType.NO,
           DistributedType.MULTI_CPU,
           DistributedType.MULTI_GPU,
       ]:
           raise NotImplementedError('LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'						)
       _lowercase     			=						enabled and accelerator.distributed_type != DistributedType.NO
       _lowercase     			=						0
       if self.enabled:
           _lowercase     			=						accelerator
           _lowercase     			=						model
           _lowercase     			=						local_sgd_steps

   def       SCREAMING_SNAKE_CASE__					(     self:						str						)	->		List[Any]:


       """simple docstring"""



       self.num_steps += 1
       if not self.enabled:
           return

       if self.num_steps % self.local_sgd_steps == 0:
           self._sync_and_avg_model_params()

   def       SCREAMING_SNAKE_CASE__					(     self:						Optional[int]						)	->		Dict:


       """simple docstring"""



       self.accelerator.wait_for_everyone()
       with self.accelerator.autocast():
           for param in self.model.parameters():
               _lowercase     			=						self.accelerator.reduce(param.data ,							reduction='mean'						)
