'''simple docstring'''




import torch

from accelerate import Accelerator, DistributedType

class      lowerCamelCase_     :
      '''simple docstring'''

      def __enter__(	self						:    Dict	):
             if self.enabled:
                    _UpperCAmelCase					:  str											=   self.model.no_sync()
                    self.model_sync_obj.__enter__()

             return self




      def __exit__(	self						:    Tuple						, A						:    str						, A						:    str						, A						:    List[str]	):
             if self.enabled:
                    # Average all models on exit
                    self._sync_and_avg_model_params()
                    self.model_sync_obj.__exit__(A						, A						, A	)




      def __init__(	self						:    Optional[Any]						, A						:    Accelerator						, A						:    torch.nn.Module						, A						:    int						, A						:    bool = True	):
             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)"	)
             _UpperCAmelCase					:  Optional[Any]											=   enabled and accelerator.distributed_type != DistributedType.NO
             _UpperCAmelCase					:  Any											=   0
             if self.enabled:
                    _UpperCAmelCase					:  List[str]											=   accelerator
                    _UpperCAmelCase					:  str											=   model
                    _UpperCAmelCase					:  List[Any]											=   local_sgd_steps




      def 					_A     (	self						:    List[Any]	):
             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 					_A     (	self						:    List[str]	):
             self.accelerator.wait_for_everyone()
             with self.accelerator.autocast():
                    for param in self.model.parameters():
                           _UpperCAmelCase					:  Tuple											=   self.accelerator.reduce(param.data						, reduction="mean"	)


'''simple docstring'''




def      UpperCamelCase_							( _UpperCAmelCase  :				int      ,     _UpperCAmelCase  :				list[tuple[int, int, int]]   )   ->   list[tuple[int, int, int]]:


       """simple docstring"""







       _UpperCAmelCase					:  Optional[int]											=   sorted(_UpperCAmelCase      ,     key=lambda _UpperCAmelCase   : edge[2]   )

       _UpperCAmelCase					:  Optional[int]											=   list(range(_UpperCAmelCase   )   )

       def find_parent(_UpperCAmelCase  :				Dict   ):
              if i != parent[i]:
                     _UpperCAmelCase					:  Tuple											=   find_parent(parent[i]   )
              return parent[i]

       _UpperCAmelCase					:  Union[str, Any]											=   0
       _UpperCAmelCase					:  Dict											=   []

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

       return minimum_spanning_tree


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

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

  kruskal(num_nodes, edges)

