import sys
from collections import defaultdict
class SCREAMING_SNAKE_CASE_						:







   def __init__(			self		:		Any							):





    """simple docstring"""


    UpperCamelCase          =	[]







   def 		lowerCamelCase_     (			self		:		List[str]					,					lowerCamelCase_		:		Dict							):





    """simple docstring"""


    return self.node_position[vertex]







   def 		lowerCamelCase_     (			self		:		int					,					lowerCamelCase_		:		int					,					lowerCamelCase_		:		Optional[Any]							):





    """simple docstring"""


    UpperCamelCase          =	pos







   def 		lowerCamelCase_     (			self		:		List[str]					,					lowerCamelCase_		:		Any					,					lowerCamelCase_		:		Tuple					,					lowerCamelCase_		:		str					,					lowerCamelCase_		:		Tuple							):





    """simple docstring"""


    if start > size // 2 - 1:
     return
    else:
     if 2 * start + 2 >= size:
      UpperCamelCase          =	2 * start + 1
     else:
      if heap[2 * start + 1] < heap[2 * start + 2]:
       UpperCamelCase          =	2 * start + 1
      else:
       UpperCamelCase          =	2 * start + 2
     if heap[smallest_child] < heap[start]:
      UpperCamelCase          =	heap[smallest_child], positions[smallest_child]
      UpperCamelCase          =	(
          heap[start],
          positions[start],
      )
      UpperCamelCase          =	temp, tempa

      UpperCamelCase          =	self.get_position(positions[smallest_child]							)
      self.set_position(
          positions[smallest_child]					,					self.get_position(positions[start]							)							)
      self.set_position(positions[start]					,					SCREAMING_SNAKE_CASE_							)

      self.top_to_bottom(SCREAMING_SNAKE_CASE_					,					SCREAMING_SNAKE_CASE_					,					SCREAMING_SNAKE_CASE_					,					SCREAMING_SNAKE_CASE_							)







   def 		lowerCamelCase_     (			self		:		Any					,					lowerCamelCase_		:		Union[str, Any]					,					lowerCamelCase_		:		Dict					,					lowerCamelCase_		:		int					,					lowerCamelCase_		:		int							):





    """simple docstring"""


    UpperCamelCase          =	position[index]

    while index != 0:
     UpperCamelCase          =	int((index - 2) / 2							) if index % 2 == 0 else int((index - 1) / 2							)

     if val < heap[parent]:
      UpperCamelCase          =	heap[parent]
      UpperCamelCase          =	position[parent]
      self.set_position(position[parent]					,					SCREAMING_SNAKE_CASE_							)
     else:
      UpperCamelCase          =	val
      UpperCamelCase          =	temp
      self.set_position(SCREAMING_SNAKE_CASE_					,					SCREAMING_SNAKE_CASE_							)
      break
     UpperCamelCase          =	parent
    else:
     UpperCamelCase          =	val
     UpperCamelCase          =	temp
     self.set_position(SCREAMING_SNAKE_CASE_					,					0							)







   def 		lowerCamelCase_     (			self		:		Union[str, Any]					,					lowerCamelCase_		:		List[Any]					,					lowerCamelCase_		:		List[Any]							):





    """simple docstring"""


    UpperCamelCase          =	len(SCREAMING_SNAKE_CASE_							) // 2 - 1
    for i in range(SCREAMING_SNAKE_CASE_					,					-1					,					-1							):
     self.top_to_bottom(SCREAMING_SNAKE_CASE_					,					SCREAMING_SNAKE_CASE_					,					len(SCREAMING_SNAKE_CASE_							)					,					SCREAMING_SNAKE_CASE_							)







   def 		lowerCamelCase_     (			self		:		Any					,					lowerCamelCase_		:		int					,					lowerCamelCase_		:		Any							):





    """simple docstring"""


    UpperCamelCase          =	positions[0]
    UpperCamelCase          =	sys.maxsize
    self.top_to_bottom(SCREAMING_SNAKE_CASE_					,					0					,					len(SCREAMING_SNAKE_CASE_							)					,					SCREAMING_SNAKE_CASE_							)
    return temp





def        lowercase(     UpperCamelCase_    )						->     List[Any]:







 '''simple docstring'''
 UpperCamelCase          =	Heap()

 UpperCamelCase          =	[0] * len(lowerCAmelCase__    )
 UpperCamelCase          =	[-1] * len(lowerCAmelCase__    )  # Neighboring Tree Vertex of selected vertex
 # Minimum Distance of explored vertex with neighboring vertex of partial tree
 # formed in graph
 UpperCamelCase          =	[]  # Heap of Distance of vertices from their neighboring vertex
 UpperCamelCase          =	[]

 for vertex in range(len(lowerCAmelCase__    )    ):
  distance_tv.append(sys.maxsize    )
  positions.append(lowerCAmelCase__    )
  heap.node_position.append(lowerCAmelCase__    )

 UpperCamelCase          =	[]
 UpperCamelCase          =	1
 UpperCamelCase          =	sys.maxsize
 for neighbor, distance in adjacency_list[0]:
  UpperCamelCase          =	0
  UpperCamelCase          =	distance
 heap.heapify(lowerCAmelCase__				, lowerCAmelCase__    )

 for _ in range(1				, len(lowerCAmelCase__    )    ):
  UpperCamelCase          =	heap.delete_minimum(lowerCAmelCase__				, lowerCAmelCase__    )
  if visited[vertex] == 0:
   tree_edges.append((nbr_tv[vertex], vertex)    )
   UpperCamelCase          =	1
   for neighbor, distance in adjacency_list[vertex]:
    if (
        visited[neighbor] == 0
        and distance < distance_tv[heap.get_position(lowerCAmelCase__    )]
    ):
     UpperCamelCase          =	distance
     heap.bottom_to_top(
         lowerCAmelCase__				, heap.get_position(lowerCAmelCase__    )				, lowerCAmelCase__				, lowerCAmelCase__    )
     UpperCamelCase          =	vertex
 return tree_edges


if __name__ == "__main__":  # pragma: no cover
     # < --------- Prims Algorithm --------- >
     _SCREAMING_SNAKE_CASE      						=	int(input("""Enter number of edges: """).strip())
     _SCREAMING_SNAKE_CASE      						=	defaultdict(list)
     for _ in range(edges_number):
          _SCREAMING_SNAKE_CASE      						=	[int(x) for x in input().strip().split()]
          adjacency_list[edge[0]].append([edge[1], edge[2]])
          adjacency_list[edge[1]].append([edge[0], edge[2]])
     print(prisms_algorithm(adjacency_list))





"""simple docstring"""







import inspect
import os
import unittest

import torch

import accelerate
from accelerate import Accelerator
from accelerate.test_utils import execute_subprocess_async, require_multi_gpu
from accelerate.utils import patch_environment







class       UpperCamelCase__   (	unittest.TestCase  ):




      """simple docstring"""




      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]       ):
        lowerCAmelCase_   :				Union[str, Any]								= inspect.getfile(accelerate.test_utils       )
        lowerCAmelCase_   :				Dict								= os.path.sep.join(mod_file.split(os.path.sep       )[:-1] + ['scripts', 'test_script.py']       )
        lowerCAmelCase_   :				int								= os.path.sep.join(
            mod_file.split(os.path.sep       )[:-1] + ['scripts', 'test_distributed_data_loop.py']       )
        lowerCAmelCase_   :				Union[str, Any]								= os.path.sep.join(mod_file.split(os.path.sep       )[:-1] + ['scripts', 'test_ops.py']       )



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



      @require_multi_gpu
      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[Any]       ):
        print(F"Found {torch.cuda.device_count()} devices."       )
        lowerCAmelCase_   :				int								= ['torchrun', F"--nproc_per_node={torch.cuda.device_count()}", self.operation_file_path]
        print(F"Command: {cmd}"       )
        with patch_environment(omp_num_threads=1       ):
          execute_subprocess_async(SCREAMING_SNAKE_CASE_    ,			env=os.environ.copy()       )



      @require_multi_gpu
      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]       ):
        lowerCAmelCase_   :				List[Any]								= ['torchrun', F"--nproc_per_node={torch.cuda.device_count()}", inspect.getfile(self.__class__       )]
        with patch_environment(omp_num_threads=1       ):
          execute_subprocess_async(SCREAMING_SNAKE_CASE_    ,			env=os.environ.copy()       )





      @require_multi_gpu
      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        print(F"Found {torch.cuda.device_count()} devices, using 2 devices only"       )
        lowerCAmelCase_   :				Any								= ['torchrun', F"--nproc_per_node={torch.cuda.device_count()}", self.data_loop_file_path]
        with patch_environment(omp_num_threads=1    ,			cuda_visible_devices='0,1'       ):
          execute_subprocess_async(SCREAMING_SNAKE_CASE_    ,			env=os.environ.copy()       )


if __name__ == "__main__":
     lowercase__		:				Dict          =	Accelerator()
     lowercase__		:				List[Any]          =	(accelerator.state.process_index + 2, 1_0)
     lowercase__		:				Any          =	torch.randint(0, 1_0, shape).to(accelerator.device)

     lowercase__		:				List[Any]          =	""""""

     lowercase__		:				Union[str, Any]          =	accelerator.pad_across_processes(tensor)
     if tensora.shape[0] != accelerator.state.num_processes + 1:
          error_msg += f"Found shape {tensora.shape} but should have {accelerator.state.num_processes + 1} at dim 0."
     if not torch.equal(tensora[: accelerator.state.process_index + 2], tensor):
          error_msg += "Tensors have different values."
     if not torch.all(tensora[accelerator.state.process_index + 2 :] == 0):
          error_msg += "Padding was not done with the right value (0)."

     lowercase__		:				Optional[Any]          =	accelerator.pad_across_processes(tensor, pad_first=True)
     if tensora.shape[0] != accelerator.state.num_processes + 1:
          error_msg += f"Found shape {tensora.shape} but should have {accelerator.state.num_processes + 1} at dim 0."
     lowercase__		:				Any          =	accelerator.state.num_processes - accelerator.state.process_index - 1
     if not torch.equal(tensora[index:], tensor):
          error_msg += "Tensors have different values."
     if not torch.all(tensora[:index] == 0):
          error_msg += "Padding was not done with the right value (0)."

     # Raise error at the end to make sure we don't stop at the first failure.
     if len(error_msg) > 0:
          raise ValueError(error_msg)





