




'''simple docstring'''


class        A					:







							def __init__(						self :						Dict							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						Any=None							,    lowerCAmelCase_ :						Dict=None      )    ->							Union[str, Any]:


														"""simple docstring"""


														_a			  =       data
														_a			  =       previous
														_a			  =       next_node







							def __str__(						self :						str      )    ->							str:


														"""simple docstring"""


														return F'{self.data}'







							def      __lowerCAmelCase    (						self :						Dict      )    ->							int:


														"""simple docstring"""


														return self.data







							def      __lowerCAmelCase    (						self :						Union[str, Any]      )    ->							Any:


														"""simple docstring"""


														return self.next







							def      __lowerCAmelCase    (						self :						Optional[Any]      )    ->							Union[str, Any]:


														"""simple docstring"""


														return self.previous



class        A					:







							def __init__(						self :						Optional[int]							,    lowerCAmelCase_ :						Optional[Any]      )    ->							Optional[Any]:


														"""simple docstring"""


														_a			  =       head







							def __iter__(						self :						Optional[int]      )    ->							Union[str, Any]:


														"""simple docstring"""


														return self







							def      __lowerCAmelCase    (						self :						Optional[int]      )    ->							Optional[int]:


														"""simple docstring"""


														if not self.current:
																					raise StopIteration
														else:
																					_a			  =       self.current.get_data()
																					_a			  =       self.current.get_next()
																					return value



class        A					:







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


														"""simple docstring"""


														_a			  =       None  # First node in list
														_a			  =       None  # Last node in list







							def __str__(						self :						Optional[Any]      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.head
														_a			  =       []
														while current is not None:
																					nodes.append(current.get_data()      )
																					_a			  =       current.get_next()
														return " ".join(str(lowerCAmelCase_      ) for node in nodes      )







							def __contains__(						self :						Dict							,    lowerCAmelCase_ :						int      )    ->							Dict:


														"""simple docstring"""


														_a			  =       self.head
														while current:
																					if current.get_data() == value:
																												return True
																					_a			  =       current.get_next()
														return False







							def __iter__(						self :						str      )    ->							List[Any]:


														"""simple docstring"""


														return LinkedListIterator(self.head      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														if self.head:
																					return self.head.get_data()
														return None







							def      __lowerCAmelCase    (						self :						Tuple      )    ->							List[Any]:


														"""simple docstring"""


														if self.tail:
																					return self.tail.get_data()
														return None







							def      __lowerCAmelCase    (						self :						Any							,    lowerCAmelCase_ :						Node      )    ->							None:


														"""simple docstring"""


														if self.head is None:
																					_a			  =       node
																					_a			  =       node
														else:
																					self.insert_before_node(self.head							,    lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						str							,    lowerCAmelCase_ :						Node      )    ->							None:


														"""simple docstring"""


														if self.head is None:
																					self.set_head(lowerCAmelCase_      )
														else:
																					self.insert_after_node(self.tail							,    lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[str]							,    lowerCAmelCase_ :						int      )    ->							None:


														"""simple docstring"""


														_a			  =       Node(lowerCAmelCase_      )
														if self.head is None:
																					self.set_head(lowerCAmelCase_      )
														else:
																					self.set_tail(lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						Optional[Any]							,    lowerCAmelCase_ :						Node							,    lowerCAmelCase_ :						Node      )    ->							None:


														"""simple docstring"""


														_a			  =       node
														_a			  =       node.previous

														if node.get_previous() is None:
																					_a			  =       node_to_insert
														else:
																					_a			  =       node_to_insert

														_a			  =       node_to_insert







							def      __lowerCAmelCase    (						self :						Union[str, Any]							,    lowerCAmelCase_ :						Node							,    lowerCAmelCase_ :						Node      )    ->							None:


														"""simple docstring"""


														_a			  =       node
														_a			  =       node.next

														if node.get_next() is None:
																					_a			  =       node_to_insert
														else:
																					_a			  =       node_to_insert

														_a			  =       node_to_insert







							def      __lowerCAmelCase    (						self :						List[str]							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						int      )    ->							None:


														"""simple docstring"""


														_a			  =       1
														_a			  =       Node(lowerCAmelCase_      )
														_a			  =       self.head
														while node:
																					if current_position == position:
																												self.insert_before_node(lowerCAmelCase_							,    lowerCAmelCase_      )
																												return
																					current_position += 1
																					_a			  =       node.next
														self.insert_after_node(self.tail							,    lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						int							,    lowerCAmelCase_ :						int      )    ->							Node:


														"""simple docstring"""


														_a			  =       self.head
														while node:
																					if node.get_data() == item:
																												return node
																					_a			  =       node.get_next()
														raise Exception('''Node not found'''      )







							def      __lowerCAmelCase    (						self :						List[str]							,    lowerCAmelCase_ :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														if (node := self.get_node(lowerCAmelCase_      )) is not None:
																					if node == self.head:
																												_a			  =       self.head.get_next()

																					if node == self.tail:
																												_a			  =       self.tail.get_previous()

																					self.remove_node_pointers(lowerCAmelCase_      )







							@staticmethod
							def      __lowerCAmelCase    (						lowerCAmelCase_ :						Node      )    ->							None:


														"""simple docstring"""


														if node.get_next():
																					_a			  =       node.previous

														if node.get_previous():
																					_a			  =       node.next

														_a			  =       None
														_a			  =       None







							def      __lowerCAmelCase    (						self :						Union[str, Any]      )    ->							Optional[int]:


														"""simple docstring"""


														return self.head is None



def 	snake_case_					():





							'''simple docstring'''






if __name__ == "__main__":
				import doctest

				doctest.testmod()







'''simple docstring'''


import sys
from collections import defaultdict

class     A					:







							def __init__(						self :						Optional[Any]      )    ->							Union[str, Any]:


														"""simple docstring"""


														_a			  =       []







							def      __lowerCAmelCase    (						self :						Union[str, Any]							,    lowerCAmelCase_ :						List[Any]      )    ->							int:


														"""simple docstring"""


														return self.node_position[vertex]







							def      __lowerCAmelCase    (						self :						List[Any]							,    lowerCAmelCase_ :						Optional[Any]							,    lowerCAmelCase_ :						Optional[Any]      )    ->							Tuple:


														"""simple docstring"""


														_a			  =       pos







							def      __lowerCAmelCase    (						self :						Dict							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Any							,    lowerCAmelCase_ :						Dict							,    lowerCAmelCase_ :						int      )    ->							Any:


														"""simple docstring"""


														if start > size // 2 - 1:
																					return
														else:
																					if 2 * start + 2 >= size:
																												_a			  =       2 * start + 1
																					else:
																												if heap[2 * start + 1] < heap[2 * start + 2]:
																																			_a			  =       2 * start + 1
																												else:
																																			_a			  =       2 * start + 2
																					if heap[smallest_child] < heap[start]:
																												_a  ,							_a			  =       heap[smallest_child], positions[smallest_child]
																												_a  ,							_a			  =       (
																												    heap[start],
																												    positions[start],
																												)
																												_a  ,							_a			  =       temp, tempa

																												_a			  =       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 :						Optional[int]							,    lowerCAmelCase_ :						List[str]							,    lowerCAmelCase_ :						List[Any]							,    lowerCAmelCase_ :						Any							,    lowerCAmelCase_ :						Dict      )    ->							Any:


														"""simple docstring"""


														_a			  =       position[index]

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

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







							def      __lowerCAmelCase    (						self :						Any							,    lowerCAmelCase_ :						List[Any]							,    lowerCAmelCase_ :						Optional[Any]      )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       len(lowerCAmelCase_      ) // 2 - 1
														for i in range(lowerCAmelCase_							,    -1							,    -1      ):
																					self.top_to_bottom(lowerCAmelCase_							,    lowerCAmelCase_							,    len(lowerCAmelCase_      )							,    lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						str							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						int      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       positions[0]
														_a			  =       sys.maxsize
														self.top_to_bottom(lowerCAmelCase_							,    0							,    len(lowerCAmelCase_      )							,    lowerCAmelCase_      )
														return temp



def 	snake_case_					(UpperCamelCase :						Any   ):





							'''simple docstring'''


							_a			  =       Heap()

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

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

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

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


if __name__ == "__main__":  # pragma: no cover
				# < --------- Prims Algorithm --------- >
				_snake_case   :   List[str]     							=	int(input('Enter number of edges: ').strip())
				_snake_case   :   Union[str, Any]     							=	defaultdict(list)
				for _ in range(edges_number):
								_snake_case   :   Tuple     							=	[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))

