





import sys
from collections import defaultdict





class 					A_					:







       """simple docstring"""





       def __init__(     self						:						str	)    ->       Union[str, Any]:
         _lowercase						    =			[]







       def  __UpperCAmelCase			(     self						:						List[str]    ,__A						:						Any	)    ->       Union[str, Any]:
         return self.node_position[vertex]







       def  __UpperCAmelCase			(     self						:						Dict    ,__A						:						Any    ,__A						:						Tuple	)    ->       Tuple:
         _lowercase						    =			pos







       def  __UpperCAmelCase			(     self						:						Optional[Any]    ,__A						:						List[Any]    ,__A						:						List[Any]    ,__A						:						str    ,__A						:						Any	)    ->       List[str]:
         if start > size // 2 - 1:
           return
         else:
           if 2 * start + 2 >= size:
             _lowercase						    =			2 * start + 1
           else:
             if heap[2 * start + 1] < heap[2 * start + 2]:
               _lowercase						    =			2 * start + 1
             else:
               _lowercase						    =			2 * start + 2
           if heap[smallest_child] < heap[start]:
             _lowercase    ,		_lowercase						    =			heap[smallest_child], positions[smallest_child]
             _lowercase    ,		_lowercase						    =			(
                 heap[start],
                 positions[start],
             )
             _lowercase    ,		_lowercase						    =			temp, tempa

             _lowercase						    =			self.get_position(positions[smallest_child]	)
             self.set_position(
                 positions[smallest_child]    ,self.get_position(positions[start]	)	)
             self.set_position(positions[start]    ,__A	)

             self.top_to_bottom(__A    ,__A    ,__A    ,__A	)







       def  __UpperCAmelCase			(     self						:						Any    ,__A						:						Dict    ,__A						:						List[str]    ,__A						:						Optional[Any]    ,__A						:						Dict	)    ->       Optional[Any]:
         _lowercase						    =			position[index]

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

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







       def  __UpperCAmelCase			(     self						:						Optional[int]    ,__A						:						str    ,__A						:						List[Any]	)    ->       List[Any]:
         _lowercase						    =			len(__A	) // 2 - 1
         for i in range(__A    ,-1    ,-1	):
           self.top_to_bottom(__A    ,__A    ,len(__A	)    ,__A	)







       def  __UpperCAmelCase			(     self						:						Any    ,__A						:						Tuple    ,__A						:						Optional[Any]	)    ->       str:
         _lowercase						    =			positions[0]
         _lowercase						    =			sys.maxsize
         self.top_to_bottom(__A    ,0    ,len(__A	)    ,__A	)
         return temp

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:Tuple  )   ->    List[Any]:
  _lowercase						    =			Heap()

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

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

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

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


if __name__ == "__main__":  # pragma: no cover
      # < --------- Prims Algorithm --------- >
      snake_case								=							int(input("""Enter number of edges: """).strip())
      snake_case								=							defaultdict(list)
      for _ in range(edges_number):
            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"""






from ..utils import DummyObject, requires_backends



class     UpperCAmelCase    (	metaclass=__SCREAMING_SNAKE_CASE  ):
   A__		:	Optional[int]           =  ['''torch''', '''scipy''']



   def __init__(       self    :	Any							,       *__lowerCamelCase    :	List[Any]							,       **__lowerCamelCase    :	Any				):



     """simple docstring"""
     requires_backends(self							,       ['''torch''', '''scipy''']				)



   @classmethod
   def    __UpperCAmelCase    (       cls    :	Dict							,       *__lowerCamelCase    :	List[str]							,       **__lowerCamelCase    :	Tuple				):



     """simple docstring"""
     requires_backends(cls							,       ['''torch''', '''scipy''']				)





   @classmethod
   def    __UpperCAmelCase    (       cls    :	int							,       *__lowerCamelCase    :	Union[str, Any]							,       **__lowerCamelCase    :	Tuple				):



     """simple docstring"""
     requires_backends(cls							,       ['''torch''', '''scipy''']				)





