


"""simple docstring"""







import sys
from collections import defaultdict


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							[]

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         return self.node_position[vertex]

       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							pos

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         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     :     Dict								=							2 * start + 2
           if heap[smallest_child] < heap[start]:
             lowerCAmelCase						,  lowerCAmelCase     :     List[Any]								=							heap[smallest_child], positions[smallest_child]
             lowerCAmelCase						,  lowerCAmelCase     :     List[Any]								=							(
                 heap[start],
                 positions[start],
             )
             lowerCAmelCase						,  lowerCAmelCase     :     int								=							temp, tempa

             lowerCAmelCase     :     Dict								=							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        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							position[index]

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

           if val < heap[parent]:
             lowerCAmelCase     :     Optional[int]								=							heap[parent]
             lowerCAmelCase     :     Optional[int]								=							position[parent]
             self.set_position(position[parent]		,     snake_case__						)
           else:
             lowerCAmelCase     :     int								=							val
             lowerCAmelCase     :     Optional[int]								=							temp
             self.set_position(snake_case__		,     snake_case__						)
             break
           lowerCAmelCase     :     str								=							parent
         else:
           lowerCAmelCase     :     Union[str, Any]								=							val
           lowerCAmelCase     :     Tuple								=							temp
           self.set_position(snake_case__		,     0						)

       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     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        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							positions[0]
         lowerCAmelCase     :     List[Any]								=							sys.maxsize
         self.top_to_bottom(snake_case__		,     0		,     len(snake_case__						)		,     snake_case__						)
         return temp

def 					a__			(				SCREAMING_SNAKE_CASE    :    Union[str, Any]				):


  '''simple docstring'''







  lowerCAmelCase     :     List[Any]								=							Heap()

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

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

  lowerCAmelCase     :     List[str]								=							[]
  lowerCAmelCase     :     List[Any]								=							1
  lowerCAmelCase     :     Optional[int]								=							sys.maxsize
  for neighbor, distance in adjacency_list[0]:
    lowerCAmelCase     :     str								=							0
    lowerCAmelCase     :     Union[str, Any]								=							distance
  heap.heapify(SCREAMING_SNAKE_CASE				,      SCREAMING_SNAKE_CASE				)

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


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

from transformers.testing_utils import check_json_file_has_correct_format






class  lowerCAmelCase__   :
					lowerCAmelCase_        =     None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)
											lowercase_	:     Any													=       json.loads(feat_extract.to_json_string()		)
											for key, value in self.feat_extract_dict.items():
																	self.assertEqual(obj[key]				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     str													=       os.path.join(__SCREAMING_SNAKE_CASE				,							'''feat_extract.json'''		)
																	feat_extract_first.to_json_file(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_json_file(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     Union[str, Any]													=       feat_extract_first.save_pretrained(__SCREAMING_SNAKE_CASE		)[0]
																	check_json_file_has_correct_format(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_pretrained(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       self.feature_extraction_class()
											self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)



