


import sys
from collections import defaultdict



class 				_UpperCamelCase			:

   '''simple docstring'''







   def __init__(	self	:			Optional[Any]				):






         '''simple docstring'''



         __lowerCamelCase  :   Any							    =    []

   def 	_snake_case     (	self	:			Tuple							,	_lowerCamelCase	:			Any				):






         '''simple docstring'''



         return self.node_position[vertex]

   def 	_snake_case     (	self	:			Any							,	_lowerCamelCase	:			List[str]							,	_lowerCamelCase	:			Dict				):






         '''simple docstring'''



         __lowerCamelCase  :   Tuple							    =    pos

   def 	_snake_case     (	self	:			str							,	_lowerCamelCase	:			Dict							,	_lowerCamelCase	:			List[Any]							,	_lowerCamelCase	:			Optional[int]							,	_lowerCamelCase	:			Optional[int]				):






         '''simple docstring'''



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

                     __lowerCamelCase  :   Optional[int]							    =    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 	_snake_case     (	self	:			Optional[int]							,	_lowerCamelCase	:			int							,	_lowerCamelCase	:			List[Any]							,	_lowerCamelCase	:			Optional[int]							,	_lowerCamelCase	:			Any				):






         '''simple docstring'''



         __lowerCamelCase  :   Union[str, Any]							    =    position[index]

         while index != 0:
               __lowerCamelCase  :   Union[str, Any]							    =    int((index - 2) / 2				) if index % 2 == 0 else int((index - 1) / 2				)

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

   def 	_snake_case     (	self	:			Tuple							,	_lowerCamelCase	:			Union[str, Any]							,	_lowerCamelCase	:			Optional[int]				):






         '''simple docstring'''



         __lowerCamelCase  :   int							    =    len(_lowerCamelCase				) // 2 - 1
         for i in range(_lowerCamelCase							,	-1							,	-1				):
               self.top_to_bottom(_lowerCamelCase							,	_lowerCamelCase							,	len(_lowerCamelCase				)							,	_lowerCamelCase				)


   def 	_snake_case     (	self	:			Optional[Any]							,	_lowerCamelCase	:			Any							,	_lowerCamelCase	:			str				):






         '''simple docstring'''



         __lowerCamelCase  :   Union[str, Any]							    =    positions[0]
         __lowerCamelCase  :   Dict							    =    sys.maxsize
         self.top_to_bottom(_lowerCamelCase							,	0							,	len(_lowerCamelCase				)							,	_lowerCamelCase				)
         return temp





def 	_UpperCAmelCase							(  UpperCAmelCase   :      Optional[int]   ):
      """simple docstring"""




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

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

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

      __lowerCamelCase  :   Optional[Any]							    =    []
      __lowerCamelCase  :   Optional[Any]							    =    1
      __lowerCamelCase  :   Tuple							    =    sys.maxsize
      for neighbor, distance in adjacency_list[0]:
            __lowerCamelCase  :   Union[str, Any]							    =    0
            __lowerCamelCase  :   Union[str, Any]							    =    distance
      heap.heapify(__UpperCAmelCase    ,						__UpperCAmelCase   )

      for _ in range(1    ,						len(__UpperCAmelCase   )   ):
            __lowerCamelCase  :   Union[str, Any]							    =    heap.delete_minimum(__UpperCAmelCase    ,						__UpperCAmelCase   )
            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(__UpperCAmelCase   )]
                        ):
                              __lowerCamelCase  :   Optional[int]							    =    distance
                              heap.bottom_to_top(
                                  __UpperCAmelCase    ,						heap.get_position(__UpperCAmelCase   )    ,						__UpperCAmelCase    ,						__UpperCAmelCase   )
                              __lowerCamelCase  :   Tuple							    =    vertex
      return tree_edges


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








import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


a_      :      int    =     '\\n    Text data.\n    Second line of data.'

a_      :      Optional[Any]    =     'file'






@pytest.fixture(scope='''session'''       )
def     __a					(		__UpperCAmelCase       ):
 a__												= tmp_path_factory.mktemp('''data'''       ) / (FILE_PATH + '''.zstd''')
 a__												= bytes(__UpperCAmelCase							,  '''utf-8'''       )
 with zstd.open(__UpperCAmelCase							,  '''wb'''       ) as f:
  f.write(__UpperCAmelCase       )
 return path






@pytest.fixture
def     __a					(		__UpperCAmelCase       ):
 with open(os.path.join(tmpfs.local_root_dir							,  __UpperCAmelCase       )							,  '''w'''       ) as f:
  f.write(__UpperCAmelCase       )
 return FILE_PATH






@pytest.mark.parametrize('''compression_format'''							,  ['''gzip''', '''xz''', '''zstd''']       )
def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= {'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
 a__												= input_paths[compression_format]
 a__												= tmp_path / '''cache'''
 a__												= DownloadConfig(cache_dir=__UpperCAmelCase							,  extract_compressed_file=__UpperCAmelCase       )
 a__												= cached_path(__UpperCAmelCase							,  download_config=__UpperCAmelCase       )
 with open(__UpperCAmelCase       ) as f:
  a__												= f.read()
 with open(__UpperCAmelCase       ) as f:
  a__												= f.read()
 assert extracted_file_content == expected_file_content






@pytest.mark.parametrize('''default_extracted'''							,  [True, False]       )
@pytest.mark.parametrize('''default_cache_dir'''							,  [True, False]       )
def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= '''custom_cache'''
 a__												= '''custom_extracted_dir'''
 a__												= tmp_path / '''custom_extracted_path'''
 if default_extracted:
  a__												= ('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
 else:
  monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR'''							,  __UpperCAmelCase       )
  monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''							,  str(__UpperCAmelCase       )       )
  a__												= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

 a__												= xz_file
 a__												= (
     DownloadConfig(extract_compressed_file=__UpperCAmelCase       )
     if default_cache_dir
     else DownloadConfig(cache_dir=tmp_path / custom_cache_dir							,  extract_compressed_file=__UpperCAmelCase       )
 )
 a__												= cached_path(__UpperCAmelCase							,  download_config=__UpperCAmelCase       )
 assert Path(__UpperCAmelCase       ).parent.parts[-2:] == expected






def     __a					(		__UpperCAmelCase       ):
 # absolute path
 a__												= str(Path(__UpperCAmelCase       ).resolve()       )
 assert cached_path(__UpperCAmelCase       ) == text_file
 # relative path
 a__												= str(Path(__UpperCAmelCase       ).resolve().relative_to(Path(os.getcwd()       )       )       )
 assert cached_path(__UpperCAmelCase       ) == text_file






def     __a					(		__UpperCAmelCase       ):
 # absolute path
 a__												= str(tmp_path.resolve() / '''__missing_file__.txt'''       )
 with pytest.raises(__UpperCAmelCase       ):
  cached_path(__UpperCAmelCase       )
 # relative path
 a__												= '''./__missing_file__.txt'''
 with pytest.raises(__UpperCAmelCase       ):
  cached_path(__UpperCAmelCase       )






def     __a					(		__UpperCAmelCase       ):
 a__												= get_from_cache(f"tmp://{tmpfs_file}"       )
 with open(__UpperCAmelCase       ) as f:
  a__												= f.read()
 assert output_file_content == FILE_CONTENT






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		):
 with pytest.raises(__UpperCAmelCase       ):
  cached_path('''https://huggingface.co'''       )






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		__UpperCAmelCase       ):
 a__												= tmp_path_factory.mktemp('''data'''       ) / '''file.html'''
 with pytest.raises(__UpperCAmelCase       ):
  http_get('''https://huggingface.co'''							,  temp_file=__UpperCAmelCase       )
 with pytest.raises(__UpperCAmelCase       ):
  http_head('''https://huggingface.co'''       )






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		__UpperCAmelCase       ):
 a__												= tmp_path_factory.mktemp('''data'''       ) / '''file.html'''
 with pytest.raises(__UpperCAmelCase       ):
  ftp_get('''ftp://huggingface.co'''							,  temp_file=__UpperCAmelCase       )
 with pytest.raises(__UpperCAmelCase       ):
  ftp_head('''ftp://huggingface.co'''       )






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		__UpperCAmelCase       ):
 a__												= tmp_path_factory.mktemp('''data'''       ) / '''file.html'''
 with pytest.raises(__UpperCAmelCase       ):
  fsspec_get('''s3://huggingface.co'''							,  temp_file=__UpperCAmelCase       )
 with pytest.raises(__UpperCAmelCase       ):
  fsspec_head('''s3://huggingface.co'''       )





