



'''simple docstring'''






import sys
from collections import defaultdict

class 				SCREAMING_SNAKE_CASE:







	"""simple docstring"""






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







	def      A	(						self			:     str		,			__snake_case			:     Any		)			->		Optional[int]:
								return self.node_position[vertex]







	def      A	(						self			:     Dict		,			__snake_case			:     Optional[int]		,			__snake_case			:     Optional[Any]		)			->		Union[str, Any]:
								UpperCAmelCase :       Optional[Any] 							=		pos







	def      A	(						self			:     Union[str, Any]		,			__snake_case			:     Optional[int]		,			__snake_case			:     Dict		,			__snake_case			:     Dict		,			__snake_case			:     str		)			->		Dict:
								if start > size // 2 - 1:
															return
								else:
															if 2 * start + 2 >= size:
																						UpperCAmelCase :       Union[str, Any] 							=		2 * start + 1
															else:
																						if heap[2 * start + 1] < heap[2 * start + 2]:
																													UpperCAmelCase :       Tuple 							=		2 * start + 1
																						else:
																													UpperCAmelCase :       List[str] 							=		2 * start + 2
															if heap[smallest_child] < heap[start]:
																						UpperCAmelCase							,		UpperCAmelCase :       str 							=		heap[smallest_child], positions[smallest_child]
																						UpperCAmelCase							,		UpperCAmelCase :       str 							=		(
																						    heap[start],
																						    positions[start],
																						)
																						UpperCAmelCase							,		UpperCAmelCase :       Any 							=		temp, tempa

																						UpperCAmelCase :       Union[str, Any] 							=		self.get_position(positions[smallest_child]		)
																						self.set_position(
																						    positions[smallest_child]		,			self.get_position(positions[start]		)		)
																						self.set_position(positions[start]		,			__snake_case		)

																						self.top_to_bottom(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		)







	def      A	(						self			:     Tuple		,			__snake_case			:     Any		,			__snake_case			:     Optional[Any]		,			__snake_case			:     Tuple		,			__snake_case			:     str		)			->		Dict:
								UpperCAmelCase :       Union[str, Any] 							=		position[index]

								while index != 0:
															UpperCAmelCase :       List[str] 							=		int((index - 2) / 2		) if index % 2 == 0 else int((index - 1) / 2		)

															if val < heap[parent]:
																						UpperCAmelCase :       List[Any] 							=		heap[parent]
																						UpperCAmelCase :       str 							=		position[parent]
																						self.set_position(position[parent]		,			__snake_case		)
															else:
																						UpperCAmelCase :       Optional[Any] 							=		val
																						UpperCAmelCase :       Dict 							=		temp
																						self.set_position(__snake_case		,			__snake_case		)
																						break
															UpperCAmelCase :       Optional[int] 							=		parent
								else:
															UpperCAmelCase :       Any 							=		val
															UpperCAmelCase :       Optional[int] 							=		temp
															self.set_position(__snake_case		,			0		)







	def      A	(						self			:     Optional[Any]		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     List[Any]		)			->		Any:
								UpperCAmelCase :       Tuple 							=		len(__snake_case		) // 2 - 1
								for i in range(__snake_case		,			-1		,			-1		):
															self.top_to_bottom(__snake_case		,			__snake_case		,			len(__snake_case		)		,			__snake_case		)







	def      A	(						self			:     Dict		,			__snake_case			:     Optional[Any]		,			__snake_case			:     int		)			->		int:
								UpperCAmelCase :       List[Any] 							=		positions[0]
								UpperCAmelCase :       Optional[int] 							=		sys.maxsize
								self.top_to_bottom(__snake_case		,			0		,			len(__snake_case		)		,			__snake_case		)
								return temp


def  snake_case_     (					_lowerCAmelCase  :						List[str]  )      ->   str:
							UpperCAmelCase :       Union[str, Any] 							=		Heap()

							UpperCAmelCase :       str 							=		[0] * len(_lowerCAmelCase  )
							UpperCAmelCase :       str 							=		[-1] * len(_lowerCAmelCase  )  # Neighboring Tree Vertex of selected vertex
							# Minimum Distance of explored vertex with neighboring vertex of partial tree
							# formed in graph
							UpperCAmelCase :       Optional[int] 							=		[]  # Heap of Distance of vertices from their neighboring vertex
							UpperCAmelCase :       List[str] 							=		[]

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

							UpperCAmelCase :       List[str] 							=		[]
							UpperCAmelCase :       Tuple 							=		1
							UpperCAmelCase :       Union[str, Any] 							=		sys.maxsize
							for neighbor, distance in adjacency_list[0]:
														UpperCAmelCase :       List[Any] 							=		0
														UpperCAmelCase :       Tuple 							=		distance
							heap.heapify(_lowerCAmelCase   ,      _lowerCAmelCase  )

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


if __name__ == "__main__":  # pragma: no cover
						# < --------- Prims Algorithm --------- >
						UpperCamelCase__:   Any								=			int(input("Enter number of edges: ").strip())
						UpperCamelCase__:   Any								=			defaultdict(list)
						for _ in range(edges_number):
												UpperCamelCase__:   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))









"""simple docstring"""





import mpmath  # for roots of unity
import numpy as np



class 						snake_case_:






     def __init__(		self     :    str    , UpperCamelCase_     :    int=None    , UpperCamelCase_     :    List[str]=None ):
           # Input as list
           lowerCAmelCase    :		str				=      list(poly_a or [0] )[:]
           lowerCAmelCase    :		Any				=      list(poly_b or [0] )[:]

           # Remove leading zero coefficients
           while self.polyA[-1] == 0:
                 self.polyA.pop()
           lowerCAmelCase    :		Optional[int]				=      len(self.polyA )

           while self.polyB[-1] == 0:
                 self.polyB.pop()
           lowerCAmelCase    :		Union[str, Any]				=      len(self.polyB )

           # Add 0 to make lengths equal a power of 2
           lowerCAmelCase    :		str				=      int(
               2 ** np.ceil(np.loga(len(self.polyA ) + len(self.polyB ) - 1 ) ) )

           while len(self.polyA ) < self.c_max_length:
                 self.polyA.append(0 )
           while len(self.polyB ) < self.c_max_length:
                 self.polyB.append(0 )
           # A complex root used for the fourier transform
           lowerCAmelCase    :		int				=      complex(mpmath.root(x=1    , n=self.c_max_length    , k=1 ) )

           # The product
           lowerCAmelCase    :		int				=      self.__multiply()






     def    lowerCamelCase__   (		self     :    List[str]    , UpperCamelCase_     :    str ):
           lowerCAmelCase    :		Optional[Any]				=      [[x] for x in self.polyA] if which == '''A''' else [[x] for x in self.polyB]
           # Corner case
           if len(UpperCamelCase_ ) <= 1:
                 return dft[0]
           #
           lowerCAmelCase    :		Tuple				=      self.c_max_length // 2
           while next_ncol > 0:
                 lowerCAmelCase    :		Dict				=      [[] for i in range(UpperCamelCase_ )]
                 lowerCAmelCase    :		List[Any]				=      self.root**next_ncol

                 # First half of next step
                 lowerCAmelCase    :		Dict				=      1
                 for j in range(self.c_max_length // (next_ncol * 2) ):
                       for i in range(UpperCamelCase_ ):
                             new_dft[i].append(dft[i][j] + current_root * dft[i + next_ncol][j] )
                       current_root *= root
                 # Second half of next step
                 lowerCAmelCase    :		int				=      1
                 for j in range(self.c_max_length // (next_ncol * 2) ):
                       for i in range(UpperCamelCase_ ):
                             new_dft[i].append(dft[i][j] - current_root * dft[i + next_ncol][j] )
                       current_root *= root
                 # Update
                 lowerCAmelCase    :		Optional[Any]				=      new_dft
                 lowerCAmelCase    :		Union[str, Any]				=      next_ncol // 2
           return dft[0]






     def    lowerCamelCase__   (		self     :    List[Any] ):
           lowerCAmelCase    :		Optional[Any]				=      self.__dft('''A''' )
           lowerCAmelCase    :		Optional[int]				=      self.__dft('''B''' )
           lowerCAmelCase    :		Any				=      [[dft_a[i] * dft_b[i] for i in range(self.c_max_length )]]
           del dft_a
           del dft_b

           # Corner Case
           if len(inverce_c[0] ) <= 1:
                 return inverce_c[0]
           # Inverse DFT
           lowerCAmelCase    :		str				=      2
           while next_ncol <= self.c_max_length:
                 lowerCAmelCase    :		Union[str, Any]				=      [[] for i in range(UpperCamelCase_ )]
                 lowerCAmelCase    :		Optional[Any]				=      self.root ** (next_ncol // 2)
                 lowerCAmelCase    :		Tuple				=      1
                 # First half of next step
                 for j in range(self.c_max_length // next_ncol ):
                       for i in range(next_ncol // 2 ):
                             # Even positions
                             new_inverse_c[i].append(
                                 (
                                     inverce_c[i][j]
                                     + inverce_c[i][j + self.c_max_length // next_ncol]
                                 )
                                 / 2 )
                             # Odd positions
                             new_inverse_c[i + next_ncol // 2].append(
                                 (
                                     inverce_c[i][j]
                                     - inverce_c[i][j + self.c_max_length // next_ncol]
                                 )
                                 / (2 * current_root) )
                       current_root *= root
                 # Update
                 lowerCAmelCase    :		Any				=      new_inverse_c
                 next_ncol *= 2
           # Unpack
           lowerCAmelCase    :		Optional[int]				=      [round(x[0].real    , 8 ) + round(x[0].imag    , 8 ) * 1j for x in inverce_c]

           # Remove leading 0's
           while inverce_c[-1] == 0:
                 inverce_c.pop()
           return inverce_c






     def __str__(		self     :    int ):
           lowerCAmelCase    :		int				=      '''A = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.polyA[: self.len_A] ) )
           lowerCAmelCase    :		str				=      '''B = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.polyB[: self.len_B] ) )
           lowerCAmelCase    :		int				=      '''A*B = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.product ) )

           return F'''{a}\n{b}\n{c}'''


# Unit tests
if __name__ == "__main__":
 import doctest

 doctest.testmod()


