

"""simple docstring"""






def 		A_	(   __UpperCamelCase     :				int       ,	__UpperCamelCase     :				list[tuple[int, int, int]]				):
		lowercase										=							sorted(snake_case_       ,	key=lambda __UpperCamelCase				: edge[2]				)

		lowercase										=							list(range(snake_case_				)				)

		def find_parent(__UpperCamelCase     :				Union[str, Any]				):
				if i != parent[i]:
						lowercase										=							find_parent(parent[i]				)
				return parent[i]

		lowercase										=							0
		lowercase										=							[]

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

		return minimum_spanning_tree


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

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

							kruskal(num_nodes, edges)

'''simple docstring'''

def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	int   ,     snake_case_				:	list[tuple[int, int, int]]							)       ->	list[tuple[int, int, int]]:
 SCREAMING_SNAKE_CASE  :  List[Any]								=		sorted(snake_case_   ,     key=lambda snake_case_							: edge[2]							)

 SCREAMING_SNAKE_CASE  :  str								=		list(range(snake_case_							)							)

 def find_parent(snake_case_				:	Union[str, Any]							):
  if i != parent[i]:
   SCREAMING_SNAKE_CASE  :  int								=		find_parent(parent[i]							)
  return parent[i]

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

 for edge in edges:
  SCREAMING_SNAKE_CASE  :  Dict								=		find_parent(edge[0]							)
  SCREAMING_SNAKE_CASE  :  Optional[int]								=		find_parent(edge[1]							)
  if parent_a != parent_b:
   minimum_spanning_tree_cost += edge[2]
   minimum_spanning_tree.append(snake_case_							)
   SCREAMING_SNAKE_CASE  :  Tuple								=		parent_b

 return minimum_spanning_tree


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

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

   kruskal(num_nodes, edges)


