


"""simple docstring"""







from __future__ import annotations

from collections import defaultdict
from dataclasses import dataclass






@dataclass
class 		_A    :







    """simple docstring"""




    UpperCAmelCase			:				int
    UpperCAmelCase			:				TreeNode | None      =			None
    UpperCAmelCase			:				TreeNode | None      =			None






def 	lowercase     (							)-> TreeNode:
  '''simple docstring'''







  return TreeNode(3    ,  TreeNode(9			)    ,  TreeNode(20    ,  TreeNode(15			)    ,  TreeNode(7			)			)			)


def 	lowercase     (							A_			)-> list[int]:
  '''simple docstring'''







  def depth_first_search(
      A_    ,  A_    ,  A_			) -> None:
    if not root:
      return

    if depth == len(A_			):
      right_view.append(root.val			)

    depth_first_search(root.right    ,  depth + 1    ,  A_			)
    depth_first_search(root.left    ,  depth + 1    ,  A_			)

  a		:						list 				=     []
  if not root:
    return right_view

  depth_first_search(A_    ,  0    ,  A_			)
  return right_view


def 	lowercase     (							A_			)-> list[int]:
  '''simple docstring'''







  def depth_first_search(
      A_    ,  A_    ,  A_			) -> None:
    if not root:
      return

    if depth == len(A_			):
      left_view.append(root.val			)

    depth_first_search(root.left    ,  depth + 1    ,  A_			)
    depth_first_search(root.right    ,  depth + 1    ,  A_			)

  a		:						list 				=     []
  if not root:
    return left_view

  depth_first_search(A_    ,  0    ,  A_			)
  return left_view


def 	lowercase     (							A_			)-> list[int]:
  '''simple docstring'''







  def breadth_first_search(A_    ,  A_			) -> None:
    a		:						List[str] 				=     [(root, 0)]
    a		:						List[Any] 				=     defaultdict(A_			)

    while queue:
      a		:						Union[str, Any] 				=     queue.pop(0			)
      a				,						a		:						int 				=     first

      lookup[hd].append(node.val			)

      if node.left:
        queue.append((node.left, hd - 1)			)
      if node.right:
        queue.append((node.right, hd + 1)			)

    for pair in sorted(lookup.items()    ,  key=lambda A_			: each[0]			):
      top_view.append(pair[1][0]			)

  a		:						list 				=     []
  if not root:
    return top_view

  breadth_first_search(A_    ,  A_			)
  return top_view


def 	lowercase     (							A_			)-> list[int]:
  '''simple docstring'''







  from collections import defaultdict

  def breadth_first_search(A_    ,  A_			) -> None:
    a		:						Optional[int] 				=     [(root, 0)]
    a		:						str 				=     defaultdict(A_			)

    while queue:
      a		:						int 				=     queue.pop(0			)
      a				,						a		:						Optional[Any] 				=     first
      lookup[hd].append(node.val			)

      if node.left:
        queue.append((node.left, hd - 1)			)
      if node.right:
        queue.append((node.right, hd + 1)			)

    for pair in sorted(lookup.items()    ,  key=lambda A_			: each[0]			):
      bottom_view.append(pair[1][-1]			)

  a		:						list 				=     []
  if not root:
    return bottom_view

  breadth_first_search(A_    ,  A_			)
  return bottom_view


if __name__ == "__main__":
 import doctest

 doctest.testmod()










"""simple docstring"""







def 	lowercase     (							A_    ,  A_			)-> list[tuple[int, int, int]]:
  '''simple docstring'''







  a		:						Union[str, Any] 				=     sorted(A_    ,  key=lambda A_			: edge[2]			)

  a		:						List[Any] 				=     list(range(A_			)			)

  def find_parent(A_			):
    if i != parent[i]:
      a		:						Dict 				=     find_parent(parent[i]			)
    return parent[i]

  a		:						Optional[Any] 				=     0
  a		:						Optional[int] 				=     []

  for edge in edges:
    a		:						List[str] 				=     find_parent(edge[0]			)
    a		:						int 				=     find_parent(edge[1]			)
    if parent_a != parent_b:
      minimum_spanning_tree_cost += edge[2]
      minimum_spanning_tree.append(A_			)
      a		:						Tuple 				=     parent_b

  return minimum_spanning_tree


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

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

 kruskal(num_nodes, edges)






