"""simple docstring"""






import sys
from collections import defaultdict
class        snake_case :




					"""simple docstring"""

					def __init__(       self     :			int    ):
									UpperCAmelCase__    =							[]







					def 	__lowerCAmelCase		(       self     :			Dict					,lowerCamelCase__     :			int    ):
									return self.node_position[vertex]







					def 	__lowerCAmelCase		(       self     :			int					,lowerCamelCase__     :			Optional[int]					,lowerCamelCase__     :			List[str]    ):
									UpperCAmelCase__    =							pos







					def 	__lowerCAmelCase		(       self     :			Dict					,lowerCamelCase__     :			Union[str, Any]					,lowerCamelCase__     :			str					,lowerCamelCase__     :			Any					,lowerCamelCase__     :			Dict    ):
									if start > size // 2 - 1:
													return
									else:
													if 2 * start + 2 >= size:
																	UpperCAmelCase__    =							2 * start + 1
													else:
																	if heap[2 * start + 1] < heap[2 * start + 2]:
																					UpperCAmelCase__    =							2 * start + 1
																	else:
																					UpperCAmelCase__    =							2 * start + 2
													if heap[smallest_child] < heap[start]:
																	UpperCAmelCase__   ,			UpperCAmelCase__    =							heap[smallest_child], positions[smallest_child]
																	UpperCAmelCase__   ,			UpperCAmelCase__    =							(
																	    heap[start],
																	    positions[start],
																	)
																	UpperCAmelCase__   ,			UpperCAmelCase__    =							temp, tempa

																	UpperCAmelCase__    =							self.get_position(positions[smallest_child]    )
																	self.set_position(
																	    positions[smallest_child]					,self.get_position(positions[start]    )    )
																	self.set_position(positions[start]					,lowerCamelCase__    )

																	self.top_to_bottom(lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			Tuple					,lowerCamelCase__     :			Optional[Any]					,lowerCamelCase__     :			Optional[int]					,lowerCamelCase__     :			Union[str, Any]					,lowerCamelCase__     :			Dict    ):
									UpperCAmelCase__    =							position[index]

									while index != 0:
													UpperCAmelCase__    =							int((index - 2) / 2    ) if index % 2 == 0 else int((index - 1) / 2    )

													if val < heap[parent]:
																	UpperCAmelCase__    =							heap[parent]
																	UpperCAmelCase__    =							position[parent]
																	self.set_position(position[parent]					,lowerCamelCase__    )
													else:
																	UpperCAmelCase__    =							val
																	UpperCAmelCase__    =							temp
																	self.set_position(lowerCamelCase__					,lowerCamelCase__    )
																	break
													UpperCAmelCase__    =							parent
									else:
													UpperCAmelCase__    =							val
													UpperCAmelCase__    =							temp
													self.set_position(lowerCamelCase__					,0    )







					def 	__lowerCAmelCase		(       self     :			str					,lowerCamelCase__     :			Tuple					,lowerCamelCase__     :			Optional[Any]    ):
									UpperCAmelCase__    =							len(lowerCamelCase__    ) // 2 - 1
									for i in range(lowerCamelCase__					,-1					,-1    ):
													self.top_to_bottom(lowerCamelCase__					,lowerCamelCase__					,len(lowerCamelCase__    )					,lowerCamelCase__    )







					def 	__lowerCAmelCase		(       self     :			Any					,lowerCamelCase__     :			Any					,lowerCamelCase__     :			List[str]    ):
									UpperCAmelCase__    =							positions[0]
									UpperCAmelCase__    =							sys.maxsize
									self.top_to_bottom(lowerCamelCase__					,0					,len(lowerCamelCase__    )					,lowerCamelCase__    )
									return temp






def 						a_		(      lowerCamelCase ):
				UpperCAmelCase__    =							Heap()

				UpperCAmelCase__    =							[0] * len(lowerCamelCase )
				UpperCAmelCase__    =							[-1] * len(lowerCamelCase )  # Neighboring Tree Vertex of selected vertex
				# Minimum Distance of explored vertex with neighboring vertex of partial tree
				# formed in graph
				UpperCAmelCase__    =							[]  # Heap of Distance of vertices from their neighboring vertex
				UpperCAmelCase__    =							[]

				for vertex in range(len(lowerCamelCase ) ):
								distance_tv.append(sys.maxsize )
								positions.append(lowerCamelCase )
								heap.node_position.append(lowerCamelCase )

				UpperCAmelCase__    =							[]
				UpperCAmelCase__    =							1
				UpperCAmelCase__    =							sys.maxsize
				for neighbor, distance in adjacency_list[0]:
								UpperCAmelCase__    =							0
								UpperCAmelCase__    =							distance
				heap.heapify(lowerCamelCase      ,    lowerCamelCase )

				for _ in range(1      ,    len(lowerCamelCase ) ):
								UpperCAmelCase__    =							heap.delete_minimum(lowerCamelCase      ,    lowerCamelCase )
								if visited[vertex] == 0:
												tree_edges.append((nbr_tv[vertex], vertex) )
												UpperCAmelCase__    =							1
												for neighbor, distance in adjacency_list[vertex]:
																if (
																    visited[neighbor] == 0
																    and distance < distance_tv[heap.get_position(lowerCamelCase )]
																):
																				UpperCAmelCase__    =							distance
																				heap.bottom_to_top(
																				    lowerCamelCase      ,    heap.get_position(lowerCamelCase )      ,    lowerCamelCase      ,    lowerCamelCase )
																				UpperCAmelCase__    =							vertex
				return tree_edges


if __name__ == "__main__":  # pragma: no cover
						# < --------- Prims Algorithm --------- >
						lowerCAmelCase__						:						Tuple		  =			int(input('Enter number of edges: ').strip())
						lowerCAmelCase__						:						Optional[int]		  =			defaultdict(list)
						for _ in range(edges_number):
												lowerCAmelCase__						:						str		  =			[int(x) for x in input().strip().split()]
												adjacency_list[edge[0]].append([edge[1], edge[2]])
												adjacency_list[edge[1]].append([edge[0], edge[2]])
						print(prisms_algorithm(adjacency_list))




"""simple docstring"""






import re



def 						a_		(      lowerCamelCase ):
				return [char.split() for char in re.split(r'[^ a-z A-Z 0-9 \s]'      ,    str_ )]



def 						a_		(      lowerCamelCase ):
				UpperCAmelCase__    =							split_input(str_ )
				return "".join(
				    [''.join([char.capitalize() for char in sub_str] ) for sub_str in string_split] )



def 						a_		(      lowerCamelCase      ,    lowerCamelCase      ,    lowerCamelCase ):
				try:
								UpperCAmelCase__    =							split_input(lowerCamelCase )
								if upper:
												UpperCAmelCase__    =							''.join(
												    [
												        separator.join([char.upper() for char in sub_str] )
												        for sub_str in string_split
												    ] )
								else:
												UpperCAmelCase__    =							''.join(
												    [
												        separator.join([char.lower() for char in sub_str] )
												        for sub_str in string_split
												    ] )
								return res_str
				except IndexError:
								return "not valid string"



def 						a_		(      lowerCamelCase ):
				return to_simple_case(lowerCamelCase )



def 						a_		(      lowerCamelCase ):
				try:
								UpperCAmelCase__    =							to_simple_case(lowerCamelCase )
								return res_str[0].lower() + res_str[1:]
				except IndexError:
								return "not valid string"



def 						a_		(      lowerCamelCase      ,    lowerCamelCase ):
				return to_complex_case(lowerCamelCase      ,    lowerCamelCase      ,    '_' )



def 						a_		(      lowerCamelCase      ,    lowerCamelCase ):
				return to_complex_case(lowerCamelCase      ,    lowerCamelCase      ,    '-' )


if __name__ == "__main__":
						__import__('doctest').testmod()



