



"""simple docstring"""







import sys
from collections import defaultdict







class       UpperCamelCase__   :




      """simple docstring"""




      def __init__(      self				:      Any       ):
        lowerCAmelCase_   :				int								= []



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      Dict       ):
        return self.node_position[vertex]



      def      SCREAMING_SNAKE_CASE__ (      self				:      int    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]       ):
        lowerCAmelCase_   :				List[Any]								= pos



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

            lowerCAmelCase_   :				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]    ,			SCREAMING_SNAKE_CASE_       )

            self.top_to_bottom(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Dict    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      int       ):
        lowerCAmelCase_   :				List[str]								= position[index]

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

          if val < heap[parent]:
            lowerCAmelCase_   :				List[str]								= heap[parent]
            lowerCAmelCase_   :				Union[str, Any]								= position[parent]
            self.set_position(position[parent]    ,			SCREAMING_SNAKE_CASE_       )
          else:
            lowerCAmelCase_   :				Any								= val
            lowerCAmelCase_   :				Optional[Any]								= temp
            self.set_position(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       )
            break
          lowerCAmelCase_   :				Any								= parent
        else:
          lowerCAmelCase_   :				List[Any]								= val
          lowerCAmelCase_   :				Optional[Any]								= temp
          self.set_position(SCREAMING_SNAKE_CASE_    ,			0       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        lowerCAmelCase_   :				List[Any]								= len(SCREAMING_SNAKE_CASE_       ) // 2 - 1
        for i in range(SCREAMING_SNAKE_CASE_    ,			-1    ,			-1       ):
          self.top_to_bottom(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			len(SCREAMING_SNAKE_CASE_       )    ,			SCREAMING_SNAKE_CASE_       )





      def      SCREAMING_SNAKE_CASE__ (      self				:      Any    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      Any       ):
        lowerCAmelCase_   :				str								= positions[0]
        lowerCAmelCase_   :				List[str]								= sys.maxsize
        self.top_to_bottom(SCREAMING_SNAKE_CASE_    ,			0    ,			len(SCREAMING_SNAKE_CASE_       )    ,			SCREAMING_SNAKE_CASE_       )
        return temp




def 				UpperCamelCase_    (    lowerCAmelCase__      :				Tuple						)						->   List[Any]:

  """simple docstring"""




  lowerCAmelCase_   :				Union[str, Any]								= Heap()

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

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

  lowerCAmelCase_   :				Any								= []
  lowerCAmelCase_   :				str								= 1
  lowerCAmelCase_   :				int								= sys.maxsize
  for neighbor, distance in adjacency_list[0]:
    lowerCAmelCase_   :				Optional[int]								= 0
    lowerCAmelCase_   :				Dict								= distance
  heap.heapify(lowerCAmelCase__    ,   lowerCAmelCase__						)

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


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







from ..utils import DummyObject, requires_backends







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      List[Any]    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      Any       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Any    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      List[str]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      int    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      Optional[int]       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      Tuple    ,			**SCREAMING_SNAKE_CASE_				:      Any       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      Dict    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Dict    ,			*SCREAMING_SNAKE_CASE_				:      List[str]    ,			**SCREAMING_SNAKE_CASE_				:      Optional[Any]       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      int    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      List[str]       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      List[Any]    ,			*SCREAMING_SNAKE_CASE_				:      Any    ,			**SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      List[str]    ,			**SCREAMING_SNAKE_CASE_				:      List[str]       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      List[str]    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      List[str]    ,			**SCREAMING_SNAKE_CASE_				:      str       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      List[Any]    ,			*SCREAMING_SNAKE_CASE_				:      Dict    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      List[str]    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[Any]    ,			*SCREAMING_SNAKE_CASE_				:      str    ,			**SCREAMING_SNAKE_CASE_				:      List[str]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      List[str]    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Any    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      str    ,			*SCREAMING_SNAKE_CASE_				:      Optional[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Any       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Union[str, Any]       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      Any    ,			**SCREAMING_SNAKE_CASE_				:      Optional[Any]       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[int]    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[int]    ,			*SCREAMING_SNAKE_CASE_				:      Tuple    ,			**SCREAMING_SNAKE_CASE_				:      Union[str, Any]       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      int    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      Union[str, Any]       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      List[str]    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Dict    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      int    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Any    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      str       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Dict    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Dict    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[int]    ,			*SCREAMING_SNAKE_CASE_				:      Tuple    ,			**SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Dict    ,			*SCREAMING_SNAKE_CASE_				:      Optional[Any]    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Optional[int]    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Dict       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[Any]    ,			*SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			**SCREAMING_SNAKE_CASE_				:      Optional[Any]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      Optional[Any]    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      Any    ,			**SCREAMING_SNAKE_CASE_				:      Any       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Union[str, Any]    ,			*SCREAMING_SNAKE_CASE_				:      Tuple    ,			**SCREAMING_SNAKE_CASE_				:      List[str]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      Optional[Any]    ,			**SCREAMING_SNAKE_CASE_				:      str       ):
        requires_backends(cls    ,			['flax']       )







class       UpperCamelCase__   (	metaclass=lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     ["""flax"""]



      def __init__(      self				:      Optional[Any]    ,			*SCREAMING_SNAKE_CASE_				:      Any    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        requires_backends(self    ,			['flax']       )



      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Tuple    ,			*SCREAMING_SNAKE_CASE_				:      Dict    ,			**SCREAMING_SNAKE_CASE_				:      Optional[int]       ):
        requires_backends(cls    ,			['flax']       )





      @classmethod
      def      SCREAMING_SNAKE_CASE__ (      cls				:      Optional[int]    ,			*SCREAMING_SNAKE_CASE_				:      str    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        requires_backends(cls    ,			['flax']       )





