






from __future__ import annotations

from typing import Generic, TypeVar

UpperCAmelCase__			 =	TypeVar('''T''')




class        snake_case_					(						__UpperCamelCase			):

						"""simple docstring"""



						pass




class        snake_case_					(						__UpperCamelCase			):

						"""simple docstring"""



						pass




class        snake_case_					(						Generic[T]			):

						"""simple docstring"""



						def __init__(self:				Dict   ,				__UpperCAmelCase:				int = 10      )						->    Dict:




											'''simple docstring'''



											__a				:	list[T]			=				[]
											__a				:	str			=				limit



						def __bool__(self:				Dict      )						->    bool:




											'''simple docstring'''



											return bool(self.stack      )



						def __str__(self:				List[str]      )						->    str:




											'''simple docstring'''



											return str(self.stack      )



						def 					UpperCAmelCase__				(self:				Any   ,				__UpperCAmelCase:				T      )						->    None:




											'''simple docstring'''



											if len(self.stack      ) >= self.limit:
																raise StackOverflowError
											self.stack.append(__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				str      )						->    T:




											'''simple docstring'''



											if not self.stack:
																raise StackUnderflowError
											return self.stack.pop()



						def 					UpperCAmelCase__				(self:				Dict      )						->    T:




											'''simple docstring'''



											if not self.stack:
																raise StackUnderflowError
											return self.stack[-1]



						def 					UpperCAmelCase__				(self:				int      )						->    bool:




											'''simple docstring'''



											return not bool(self.stack      )



						def 					UpperCAmelCase__				(self:				Optional[int]      )						->    bool:




											'''simple docstring'''



											return self.size() == self.limit



						def 					UpperCAmelCase__				(self:				Dict      )						->    int:




											'''simple docstring'''



											return len(self.stack      )



						def __contains__(self:				Optional[int]   ,				__UpperCAmelCase:				T      )						->    bool:




											'''simple docstring'''



											return item in self.stack







def 						a_      ()							->	None:



					"""simple docstring"""
					__a				:	Stack[int]			=				Stack(10			)
					assert bool(__A			) is False
					assert stack.is_empty() is True
					assert stack.is_full() is False
					assert str(__A			) == "[]"

					try:
										__a				:	Optional[int]			=				stack.pop()
										raise AssertionError  # This should not happen
					except StackUnderflowError:
										assert True  # This should happen

					try:
										__a				:	Optional[Any]			=				stack.peek()
										raise AssertionError  # This should not happen
					except StackUnderflowError:
										assert True  # This should happen

					for i in range(10			):
										assert stack.size() == i
										stack.push(__A			)

					assert bool(__A			)
					assert not stack.is_empty()
					assert stack.is_full()
					assert str(__A			) == str(list(range(10			)			)			)
					assert stack.pop() == 9
					assert stack.peek() == 8

					stack.push(100			)
					assert str(__A			) == str([0, 1, 2, 3, 4, 5, 6, 7, 8, 100]			)

					try:
										stack.push(200			)
										raise AssertionError  # This should not happen
					except StackOverflowError:
										assert True  # This should happen

					assert not stack.is_empty()
					assert stack.size() == 10

					assert 5 in stack
					assert 55 not in stack


if __name__ == "__main__":
			test_stack()













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



					"""simple docstring"""
					__a				:	str			=				sorted(__A							,					key=lambda __A			: edge[2]			)

					__a				:	int			=				list(range(__A			)			)

					def find_parent(__A			):
										if i != parent[i]:
															__a				:	Optional[Any]			=				find_parent(parent[i]			)
										return parent[i]

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

					for edge in edges:
										__a				:	Any			=				find_parent(edge[0]			)
										__a				:	Optional[Any]			=				find_parent(edge[1]			)
										if parent_a != parent_b:
															minimum_spanning_tree_cost += edge[2]
															minimum_spanning_tree.append(__A			)
															__a				:	List[str]			=				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)





