




import sys
from collections import defaultdict




class 		__lowercase						:




      """simple docstring"""





      def __init__( self      )						->							Optional[int]:
         snake_case :							Optional[int]           =			[]

      def       UpperCAmelCase ( self							, A      )						->							str:
         return self.node_position[vertex]

      def       UpperCAmelCase ( self							, A							, A      )						->							Union[str, Any]:
         snake_case :							Optional[int]           =			pos

      def       UpperCAmelCase ( self							, A							, A							, A							, A      )						->							Optional[int]:

         if start > size // 2 - 1:
            return
         else:
            if 2 * start + 2 >= size:
               snake_case :							Optional[Any]           =			2 * start + 1
            else:
               if heap[2 * start + 1] < heap[2 * start + 2]:
                  snake_case :							List[Any]           =			2 * start + 1
               else:
                  snake_case :							Dict           =			2 * start + 2
            if heap[smallest_child] < heap[start]:
               snake_case      ,   snake_case :							List[str]           =			heap[smallest_child], positions[smallest_child]
               snake_case      ,   snake_case :							Tuple           =			(
                   heap[start],
                   positions[start],
               )
               snake_case      ,   snake_case :							Dict           =			temp, tempa

               snake_case :							Tuple           =			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       UpperCAmelCase ( self							, A							, A							, A							, A      )						->							Dict:
         snake_case :							int           =			position[index]

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

            if val < heap[parent]:
               snake_case :							List[str]           =			heap[parent]
               snake_case :							Dict           =			position[parent]
               self.set_position(position[parent]							, _SCREAMING_SNAKE_CASE      )
            else:
               snake_case :							List[Any]           =			val
               snake_case :							List[Any]           =			temp
               self.set_position(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE      )
               break
            snake_case :							Dict           =			parent
         else:
            snake_case :							Optional[Any]           =			val
            snake_case :							Tuple           =			temp
            self.set_position(_SCREAMING_SNAKE_CASE							, 0      )

      def       UpperCAmelCase ( self							, A							, A      )						->							Dict:
         snake_case :							Union[str, Any]           =			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       UpperCAmelCase ( self							, A							, A      )						->							Union[str, Any]:
         snake_case :							Optional[int]           =			positions[0]
         snake_case :							Tuple           =			sys.maxsize
         self.top_to_bottom(_SCREAMING_SNAKE_CASE							, 0							, len(_SCREAMING_SNAKE_CASE      )							, _SCREAMING_SNAKE_CASE      )
         return temp




def 		SCREAMING_SNAKE_CASE__   (       lowercase	)    ->  Optional[Any]:
   snake_case :							int           =			Heap()

   snake_case :							List[str]           =			[0] * len(lowercase	)
   snake_case :							List[str]           =			[-1] * len(lowercase	)  # Neighboring Tree Vertex of selected vertex
   # Minimum Distance of explored vertex with neighboring vertex of partial tree
   # formed in graph
   snake_case :							Tuple           =			[]  # Heap of Distance of vertices from their neighboring vertex
   snake_case :							Any           =			[]

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

   snake_case :							Union[str, Any]           =			[]
   snake_case :							int           =			1
   snake_case :							Tuple           =			sys.maxsize
   for neighbor, distance in adjacency_list[0]:
      snake_case :							Any           =			0
      snake_case :							str           =			distance
   heap.heapify(lowercase		,lowercase	)

   for _ in range(1		,len(lowercase	)	):
      snake_case :							Union[str, Any]           =			heap.delete_minimum(lowercase		,lowercase	)
      if visited[vertex] == 0:
         tree_edges.append((nbr_tv[vertex], vertex)	)
         snake_case :							int           =			1
         for neighbor, distance in adjacency_list[vertex]:
            if (
                visited[neighbor] == 0
                and distance < distance_tv[heap.get_position(lowercase	)]
            ):
               snake_case :							Optional[Any]           =			distance
               heap.bottom_to_top(
                   lowercase		,heap.get_position(lowercase	)		,lowercase		,lowercase	)
               snake_case :							List[Any]           =			vertex
   return tree_edges


if __name__ == "__main__":  # pragma: no cover
       # < --------- Prims Algorithm --------- >
       lowerCamelCase			:			str								=       int(input('Enter number of edges: ').strip())
       lowerCamelCase			:			Union[str, Any]								=       defaultdict(list)
       for _ in range(edges_number):
              lowerCamelCase			:			Optional[int]								=       [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'''



def       snake_case   (	snake_case      : list			) ->  list:


    """simple docstring"""


    if any(not isinstance(snake_case					,		snake_case			) or x < 0 for x in sequence			):
        raise TypeError('Sequence must be list of non-negative integers'			)
    for _ in range(len(snake_case			)			):
        for i, (rod_upper, rod_lower) in enumerate(zip(snake_case					,		sequence[1:]			)			):
            if rod_upper > rod_lower:
                sequence[i] -= rod_upper - rod_lower
                sequence[i + 1] += rod_upper - rod_lower
    return sequence


if __name__ == "__main__":
     assert bead_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
     assert bead_sort([7, 9, 4, 3, 5]) == [3, 4, 5, 7, 9]





