





'''simple docstring'''

import multiprocessing
import os
from typing import BinaryIO, Optional, Union

import fsspec

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.json.json import Json
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader







class __a (   _snake_case			):





   def __init__(					self				:			List[Any]				,lowerCamelCase				:			NestedDataStructureLike[PathLike]				,lowerCamelCase				:			Optional[NamedSplit] = None				,lowerCamelCase				:			Optional[Features] = None				,lowerCamelCase				:			str = None				,lowerCamelCase				:			bool = False				,lowerCamelCase				:			bool = False				,lowerCamelCase				:			Optional[str] = None				,lowerCamelCase				:			Optional[int] = None				,**lowerCamelCase				:			Optional[int]				,):

      '''simple docstring'''

      super().__init__(
          lowerCamelCase				,split=lowerCamelCase				,features=lowerCamelCase				,cache_dir=lowerCamelCase				,keep_in_memory=lowerCamelCase				,streaming=lowerCamelCase				,num_proc=lowerCamelCase				,**lowerCamelCase				,)
      __SCREAMING_SNAKE_CASE      							=       field
      __SCREAMING_SNAKE_CASE      							=       path_or_paths if isinstance(lowerCamelCase				,lowerCamelCase    ) else {self.split: path_or_paths}
      __SCREAMING_SNAKE_CASE      							=       Json(
          cache_dir=lowerCamelCase				,data_files=lowerCamelCase				,features=lowerCamelCase				,field=lowerCamelCase				,**lowerCamelCase				,)





   def      UpperCAmelCase__     (					self				:			Union[str, Any]    ):

      '''simple docstring'''

      if self.streaming:
         __SCREAMING_SNAKE_CASE      							=       self.builder.as_streaming_dataset(split=self.split    )
      # Build regular (map-style) dataset
      else:
         __SCREAMING_SNAKE_CASE      							=       None
         __SCREAMING_SNAKE_CASE      							=       None
         __SCREAMING_SNAKE_CASE      							=       None
         __SCREAMING_SNAKE_CASE      							=       None

         self.builder.download_and_prepare(
             download_config=lowerCamelCase				,download_mode=lowerCamelCase				,verification_mode=lowerCamelCase				,base_path=lowerCamelCase				,num_proc=self.num_proc				,)
         __SCREAMING_SNAKE_CASE      							=       self.builder.as_dataset(
             split=self.split				,verification_mode=lowerCamelCase				,in_memory=self.keep_in_memory    )
      return dataset







class __a :





   def __init__(					self				:			Tuple				,lowerCamelCase				:			Dataset				,lowerCamelCase				:			Union[PathLike, BinaryIO]				,lowerCamelCase				:			Optional[int] = None				,lowerCamelCase				:			Optional[int] = None				,**lowerCamelCase				:			str				,):

      '''simple docstring'''

      if num_proc is not None and num_proc <= 0:
         raise ValueError(f"""num_proc {num_proc} must be an integer > 0."""    )

      __SCREAMING_SNAKE_CASE      							=       dataset
      __SCREAMING_SNAKE_CASE      							=       path_or_buf
      __SCREAMING_SNAKE_CASE      							=       batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
      __SCREAMING_SNAKE_CASE      							=       num_proc
      __SCREAMING_SNAKE_CASE      							=       """utf-8"""
      __SCREAMING_SNAKE_CASE      							=       to_json_kwargs





   def      UpperCAmelCase__     (					self				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.to_json_kwargs.pop("""path_or_buf"""				,lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       self.to_json_kwargs.pop("""orient"""				,"""records"""    )
      __SCREAMING_SNAKE_CASE      							=       self.to_json_kwargs.pop("""lines"""				,True if orient == """records""" else False    )
      __SCREAMING_SNAKE_CASE      							=       self.to_json_kwargs.pop("""index"""				,False if orient in ["""split""", """table"""] else True    )
      __SCREAMING_SNAKE_CASE      							=       self.to_json_kwargs.pop("""compression"""				,lowerCamelCase    )

      if compression not in [None, "infer", "gzip", "bz2", "xz"]:
         raise NotImplementedError(f"""`datasets` currently does not support {compression} compression"""    )

      if isinstance(self.path_or_buf				,(str, bytes, os.PathLike)    ):
         with fsspec.open(self.path_or_buf				,"""wb"""				,compression=lowerCamelCase    ) as buffer:
            __SCREAMING_SNAKE_CASE      							=       self._write(file_obj=lowerCamelCase				,orient=lowerCamelCase				,lines=lowerCamelCase				,index=lowerCamelCase				,**self.to_json_kwargs    )
      else:
         if compression:
            raise NotImplementedError(
                f"""The compression parameter is not supported when writing to a buffer, but compression={compression}"""
                """ was passed. Please provide a local path instead."""    )
         __SCREAMING_SNAKE_CASE      							=       self._write(
             file_obj=self.path_or_buf				,orient=lowerCamelCase				,lines=lowerCamelCase				,index=lowerCamelCase				,**self.to_json_kwargs    )
      return written





   def      UpperCAmelCase__     (					self				:			Optional[Any]				,lowerCamelCase				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       args

      __SCREAMING_SNAKE_CASE      							=       query_table(
          table=self.dataset.data				,key=slice(lowerCamelCase				,offset + self.batch_size    )				,indices=self.dataset._indices				,)
      __SCREAMING_SNAKE_CASE      							=       batch.to_pandas().to_json(
          path_or_buf=lowerCamelCase				,orient=lowerCamelCase				,lines=lowerCamelCase				,index=lowerCamelCase				,**lowerCamelCase    )
      if not json_str.endswith("""\n"""    ):
         json_str += "\n"
      return json_str.encode(self.encoding    )





   def      UpperCAmelCase__     (					self				:			Dict				,lowerCamelCase				:			BinaryIO				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Any				,lowerCamelCase				:			Union[str, Any]				,**lowerCamelCase				:			Any				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       0

      if self.num_proc is None or self.num_proc == 1:
         for offset in logging.tqdm(
             range(0				,len(self.dataset    )				,self.batch_size    )				,unit="""ba"""				,disable=not logging.is_progress_bar_enabled()				,desc="""Creating json from Arrow format"""				,):
            __SCREAMING_SNAKE_CASE      							=       self._batch_json((offset, orient, lines, index, to_json_kwargs)    )
            written += file_obj.write(lowerCamelCase    )
      else:
         __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       len(self.dataset    ), self.batch_size
         with multiprocessing.Pool(self.num_proc    ) as pool:
            for json_str in logging.tqdm(
                pool.imap(
                    self._batch_json				,[(offset, orient, lines, index, to_json_kwargs) for offset in range(0				,lowerCamelCase				,lowerCamelCase    )]				,)				,total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size				,unit="""ba"""				,disable=not logging.is_progress_bar_enabled()				,desc="""Creating json from Arrow format"""				,):
               written += file_obj.write(lowerCamelCase    )

      return written












'''simple docstring'''

import sys
from collections import defaultdict







class __a :





   def __init__(					self				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       []





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			List[Any]    ):

      '''simple docstring'''

      return self.node_position[vertex]





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			str				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       pos





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Union[str, Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Any    ):

      '''simple docstring'''

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

            __SCREAMING_SNAKE_CASE      							=       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      UpperCAmelCase__     (					self				:			Any				,lowerCamelCase				:			int				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Optional[Any]				,lowerCamelCase				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       position[index]

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

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





   def      UpperCAmelCase__     (					self				:			Tuple				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       len(lowerCamelCase    ) // 2 - 1
      for i in range(lowerCamelCase				,-1				,-1    ):
         self.top_to_bottom(lowerCamelCase				,lowerCamelCase				,len(lowerCamelCase    )				,lowerCamelCase    )





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       positions[0]
      __SCREAMING_SNAKE_CASE      							=       sys.maxsize
      self.top_to_bottom(lowerCamelCase				,0				,len(lowerCamelCase    )				,lowerCamelCase    )
      return temp





def 						__magic_name__       (							__UpperCAmelCase      )						->					Optional[Any]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       Heap()

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

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

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

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


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





