
'''simple docstring'''






from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
      import torch

lowercase	:      str				=       logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
      from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):




      def 		a_( cls      )				->List[str]:






             '''simple docstring'''




             return cls




def 		a_( lowerCamelCase   ,				lowerCamelCase = None   ,				lowerCamelCase = None   ,				lowerCamelCase = None   ,				lowerCamelCase = None   ,				)				->Optional[Any]:






       '''simple docstring'''




       lowercase  :		Dict						=      device
       lowercase  :		Tuple						=      shape[0]

       lowercase  :		Union[str, Any]						=      layout or torch.strided
       lowercase  :		Dict						=      device or torch.device('''cpu'''      )

       if generator is not None:
              lowercase  :		Optional[int]						=      generator.device.type if not isinstance(lowerCamelCase   ,				lowerCamelCase      ) else generator[0].device.type
              if gen_device_type != device.type and gen_device_type == "cpu":
                     lowercase  :		List[str]						=      "cpu"
                     if device != "mps":
                            logger.info(
                                f"""The passed generator was created on \'cpu\' even though a tensor on {device} was expected."""
                                f""" Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably"""
                                f""" slighly speed up this function by passing a generator that was created on the {device} device."""      )
              elif gen_device_type != device.type and gen_device_type == "cuda":
                     raise ValueError(f"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""      )

       if isinstance(lowerCamelCase   ,				lowerCamelCase      ):
              lowercase  :		Tuple						=      (1,) + shape[1:]
              lowercase  :		str						=      [
                  torch.randn(lowerCamelCase   ,				generator=generator[i]   ,				device=lowerCamelCase   ,				dtype=lowerCamelCase   ,				layout=lowerCamelCase      )
                  for i in range(lowerCamelCase      )
              ]
              lowercase  :		Dict						=      torch.cat(lowerCamelCase   ,				dim=0      ).to(lowerCamelCase      )
       else:
              lowercase  :		Optional[Any]						=      torch.randn(lowerCamelCase   ,				generator=lowerCamelCase   ,				device=lowerCamelCase   ,				dtype=lowerCamelCase   ,				layout=lowerCamelCase      ).to(lowerCamelCase      )

       return latents





def 		a_( lowerCamelCase      )				->Optional[Any]:






       '''simple docstring'''




       if is_torch_version('''<'''   ,				'''2.0.0'''      ) or not hasattr(lowerCamelCase   ,				'''_dynamo'''      ):
              return False
       return isinstance(lowerCamelCase   ,				torch._dynamo.eval_frame.OptimizedModule      )










'''simple docstring'''






def 		a_( lowerCamelCase   ,				lowerCamelCase      )				->list[tuple[int, int, int]]:






       '''simple docstring'''




       lowercase  :		Dict						=      sorted(lowerCamelCase   ,				key=lambda lowerCamelCase      : edge[2]      )

       lowercase  :		str						=      list(range(lowerCamelCase      )      )

       def find_parent(lowerCamelCase      ):
              if i != parent[i]:
                     lowercase  :		Optional[int]						=      find_parent(parent[i]      )
              return parent[i]

       lowercase  :		Union[str, Any]						=      0
       lowercase  :		Any						=      []

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

       return minimum_spanning_tree


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

      for _ in range(num_edges):
            lowercase	,	lowercase	,	lowercase	:      Optional[Any]				=       (int(x) for x in input().strip().split())
            edges.append((nodea, nodea, cost))

      kruskal(num_nodes, edges)




