

"""simple docstring"""


import os
import string
import sys


a    :Union[str, Any]			=       1 << 8

a    :Optional[Any]			=       {
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 27,
    "up": 65 + ARROW_KEY_FLAG,
    "down": 66 + ARROW_KEY_FLAG,
    "right": 67 + ARROW_KEY_FLAG,
    "left": 68 + ARROW_KEY_FLAG,
    "mod_int": 91,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 50,
    "delete": 51,
    "pg_up": 53,
    "pg_down": 54,
}

a    :Union[str, Any]			=       KEYMAP["up"]
a    :int			=       KEYMAP["left"]

if sys.platform == "win32":
  a    :int			=       []
  a    :str			=       {
      b"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
      b"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
      b"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
      b"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
      b"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
      b"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
      b"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
      b"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
  }

for i in range(10):
  a    :Dict			=       ord(str(i))




def        _lowercase    (			)				-> str:




      if os.name == "nt":
            import msvcrt

            SCREAMING_SNAKE_CASE__      :					Union[str, Any]											=		"""mbcs"""
            # Flush the keyboard buffer
            while msvcrt.kbhit():
                  msvcrt.getch()
            if len(_UpperCamelCase							) == 0:
                  # Read the keystroke
                  SCREAMING_SNAKE_CASE__      :					List[str]											=		msvcrt.getch()

                  # If it is a prefix char, get second part
                  if ch in (b"\x00", b"\xe0"):
                        SCREAMING_SNAKE_CASE__      :					Optional[int]											=		ch + msvcrt.getch()
                        # Translate actual Win chars to bullet char types
                        try:
                              SCREAMING_SNAKE_CASE__      :					Union[str, Any]											=		chr(WIN_KEYMAP[cha]							)
                              WIN_CH_BUFFER.append(chr(KEYMAP["""mod_int"""]							)							)
                              WIN_CH_BUFFER.append(_UpperCamelCase							)
                              if ord(_UpperCamelCase							) in (
                                  KEYMAP["insert"] - 1 << 9,
                                  KEYMAP["delete"] - 1 << 9,
                                  KEYMAP["pg_up"] - 1 << 9,
                                  KEYMAP["pg_down"] - 1 << 9,
                              ):
                                    WIN_CH_BUFFER.append(chr(126							)							)
                              SCREAMING_SNAKE_CASE__      :					Union[str, Any]											=		chr(KEYMAP["""esc"""]							)
                        except KeyError:
                              SCREAMING_SNAKE_CASE__      :					Dict											=		cha[1]
                  else:
                        SCREAMING_SNAKE_CASE__      :					List[str]											=		ch.decode(_UpperCamelCase							)
            else:
                  SCREAMING_SNAKE_CASE__      :					Union[str, Any]											=		WIN_CH_BUFFER.pop(0							)
      elif os.name == "posix":
            import termios
            import tty

            SCREAMING_SNAKE_CASE__      :					List[str]											=		sys.stdin.fileno()
            SCREAMING_SNAKE_CASE__      :					List[Any]											=		termios.tcgetattr(_UpperCamelCase							)
            try:
                  tty.setraw(_UpperCamelCase							)
                  SCREAMING_SNAKE_CASE__      :					Optional[int]											=		sys.stdin.read(1							)
            finally:
                  termios.tcsetattr(_UpperCamelCase     ,    termios.TCSADRAIN     ,    _UpperCamelCase							)
      return ch




def        _lowercase    (			)				-> Tuple:
      SCREAMING_SNAKE_CASE__      :					int											=		get_raw_chars()
      if ord(_UpperCamelCase							) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
            return char

      elif ord(_UpperCamelCase							) == KEYMAP["esc"]:
            SCREAMING_SNAKE_CASE__      :					List[str]											=		get_raw_chars()
            if ord(_UpperCamelCase							) == KEYMAP["mod_int"]:
                  SCREAMING_SNAKE_CASE__      :					Any											=		get_raw_chars()
                  if ord(_UpperCamelCase							) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(_UpperCamelCase							) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
                        return chr(ord(_UpperCamelCase							) + ARROW_KEY_FLAG							)
                  else:
                        return KEYMAP["undefined"]
            else:
                  return get_raw_chars()

      else:
            if char in string.printable:
                  return char
            else:
                  return KEYMAP["undefined"]








"""simple docstring"""


import sys
from collections import defaultdict
class   _UpperCamelCase  :
							'''simple docstring'''







							def __init__(     self	):
										__lowerCAmelCase				    =			[]

							def 			snake_case				(     self    ,   __a	):
										return self.node_position[vertex]

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			pos

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

																__lowerCAmelCase				    =			self.get_position(positions[smallest_child]	)
																self.set_position(
																    positions[smallest_child]    ,   self.get_position(positions[start]	)	)
																self.set_position(positions[start]    ,   __a	)

																self.top_to_bottom(__a    ,   __a    ,   __a    ,   __a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			position[index]

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

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

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			len(__a	) // 2 - 1
										for i in range(__a    ,   -1    ,   -1	):
													self.top_to_bottom(__a    ,   __a    ,   len(__a	)    ,   __a	)



							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			positions[0]
										__lowerCAmelCase				    =			sys.maxsize
										self.top_to_bottom(__a    ,   0    ,   len(__a	)    ,   __a	)
										return temp


def _lowerCamelCase	(		_UpperCamelCase      ):

			'''simple docstring'''




			__lowerCAmelCase				    =			Heap()

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

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

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

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


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




