'''simple docstring'''





from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import Any, Generic, TypeVar

__snake_case			      =    TypeVar('''T''', bound=bool)







class 			__snake_case   (     Generic[T]   ):
 def __init__(  self		,   snake_case__						)	->							int:
       '''simple docstring'''





       UpperCAmelCase    : Dict      =value
       UpperCAmelCase    : Any      =None
       UpperCAmelCase    : int      =None
 @property
 def 	UpperCAmelCase__       (  self						)	->							Dict:
       '''simple docstring'''





       return self._value






 @staticmethod
 def 	UpperCAmelCase__       (  snake_case__		,   snake_case__						)	->							List[Any]:
       '''simple docstring'''





       if not roota:
             return roota

       if not roota:
             return roota

       if roota.value > roota.value:
             UpperCAmelCase  ,						UpperCAmelCase    : int      =roota, roota

       UpperCAmelCase    : Tuple      =roota
       UpperCAmelCase    : List[str]      =roota.right
       UpperCAmelCase    : int      =roota.left
       UpperCAmelCase    : str      =SkewNode.merge(lowerCamelCase_		,   lowerCamelCase_						)

       return result







class 			__snake_case   (     Generic[T]   ):
 def __init__(  self		,   snake_case__ = ()						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : int      =None
       if data:
             for item in data:
                   self.insert(lowerCamelCase_						)
 def __bool__(  self						)	->							List[Any]:
       '''simple docstring'''





       return self._root is not None
 def __iter__(  self						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : str      =[]
       while self:
             result.append(self.pop()						)

       # Pushing items back to the heap not to clear it.
       for item in result:
             self.insert(lowerCamelCase_						)

       return iter(lowerCamelCase_						)
 def 	UpperCAmelCase__       (  self		,   snake_case__						)	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : int      =SkewNode.merge(self._root		,   SkewNode(lowerCamelCase_						)						)
 def 	UpperCAmelCase__       (  self						)	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : Dict      =self.top()
       UpperCAmelCase    : Optional[int]      =(
           SkewNode.merge(self._root.left		,   self._root.right						) if self._root else None
       )

       return result
 def 	UpperCAmelCase__       (  self						)	->							Tuple:
       '''simple docstring'''





       if not self._root:
             raise IndexError('''Can\'t get top element for the empty heap.'''						)
       return self._root.value






 def 	UpperCAmelCase__       (  self						)	->							Union[str, Any]:
       '''simple docstring'''





       UpperCAmelCase    : Tuple      =None


if __name__ == "__main__":
     import doctest

     doctest.testmod()

def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase						)->  list[tuple[int, int, int]]:






      '''simple docstring'''





      UpperCAmelCase    : List[Any]      =sorted(__lowerCAmelCase		,					key=lambda __lowerCAmelCase						: edge[2]						)

      UpperCAmelCase    : Union[str, Any]      =list(range(__lowerCAmelCase						)						)

      def find_parent(__lowerCAmelCase						):
            if i != parent[i]:
                  UpperCAmelCase    : Optional[int]      =find_parent(parent[i]						)
            return parent[i]

      UpperCAmelCase    : Optional[Any]      =0
      UpperCAmelCase    : List[str]      =[]

      for edge in edges:
            UpperCAmelCase    : Dict      =find_parent(edge[0]						)
            UpperCAmelCase    : Optional[Any]      =find_parent(edge[1]						)
            if parent_a != parent_b:
                  minimum_spanning_tree_cost += edge[2]
                  minimum_spanning_tree.append(__lowerCAmelCase						)
                  UpperCAmelCase    : Optional[Any]      =parent_b

      return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
     __snake_case      ,  __snake_case			      =    list(map(int, input().strip().split()))
     __snake_case			      =    []

     for _ in range(num_edges):
          __snake_case      ,  __snake_case      ,  __snake_case			      =    (int(x) for x in input().strip().split())
          edges.append((nodea, nodea, cost))

     kruskal(num_nodes, edges)
