




'''simple docstring'''






from __future__ import annotations




def 		a_( lowerCamelCase   ,				lowerCamelCase      )				->list:






       '''simple docstring'''




       lowercase  :		int						=      [None] * (len(lowerCamelCase      ) + len(lowerCamelCase      ))

       lowercase  :		Optional[Any]						=      0  # pointer to current index for left Half
       lowercase  :		Dict						=      0  # pointer to current index for the right Half
       lowercase  :		Optional[Any]						=      0  # pointer to current index for the sorted array Half

       while pointera < len(lowerCamelCase      ) and pointera < len(lowerCamelCase      ):
              if left_half[pointera] < right_half[pointera]:
                     lowercase  :		Union[str, Any]						=      left_half[pointera]
                     pointera += 1
                     index += 1
              else:
                     lowercase  :		Optional[int]						=      right_half[pointera]
                     pointera += 1
                     index += 1
       while pointera < len(lowerCamelCase      ):
              lowercase  :		Optional[int]						=      left_half[pointera]
              pointera += 1
              index += 1

       while pointera < len(lowerCamelCase      ):
              lowercase  :		int						=      right_half[pointera]
              pointera += 1
              index += 1

       return sorted_array




def 		a_( lowerCamelCase      )				->list:






       '''simple docstring'''




       if len(lowerCamelCase      ) <= 1:
              return array
       # the actual formula to calculate the middle element = left + (right - left) // 2
       # this avoids integer overflow in case of large N
       lowercase  :		List[Any]						=      0 + (len(lowerCamelCase      ) - 0) // 2

       # Split the array into halves till the array length becomes equal to One
       # merge the arrays of single length returned by mergeSort function and
       # pass them into the merge arrays function which merges the array
       lowercase  :		int						=      array[:middle]
       lowercase  :		str						=      array[middle:]

       return merge(merge_sort(lowerCamelCase      )   ,				merge_sort(lowerCamelCase      )      )


if __name__ == "__main__":
      import doctest

      doctest.testmod()










'''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)




