
import sys
from collections import defaultdict


class 						__lowerCAmelCase	:



      """simple docstring"""







      def __init__(      self		:       List[Any]				):
          __lowercase		:			Tuple	    =       []




      def 		snake_case_			(      self		:       Optional[Any]				,       _snake_case		:       Dict				):
          return self.node_position[vertex]




      def 		snake_case_			(      self		:       List[Any]				,       _snake_case		:       Any				,       _snake_case		:       Any				):
          __lowercase		:			int	    =       pos




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

                  __lowercase		:			int	    =       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 		snake_case_			(      self		:       List[Any]				,       _snake_case		:       Optional[int]				,       _snake_case		:       Optional[int]				,       _snake_case		:       Tuple				,       _snake_case		:       Union[str, Any]				):
          __lowercase		:			Tuple	    =       position[index]

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

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




      def 		snake_case_			(      self		:       Dict				,       _snake_case		:       str				,       _snake_case		:       Optional[int]				):
          __lowercase		:			Optional[Any]	    =       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 		snake_case_			(      self		:       Union[str, Any]				,       _snake_case		:       Dict				,       _snake_case		:       Optional[Any]				):
          __lowercase		:			List[Any]	    =       positions[0]
          __lowercase		:			Optional[int]	    =       sys.maxsize
          self.top_to_bottom(_snake_case				,       0				,       len(_snake_case				)				,       _snake_case				)
          return temp






def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						int:
    __lowercase		:			Union[str, Any]	    =       Heap()

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

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

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

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


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




import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class 						__lowerCAmelCase	(	lowerCAmelCase_ , unittest.TestCase      ):



      """simple docstring"""







      A__	:			Dict        =    None
      A__	:			Any        =    BloomTokenizerFast
      A__	:			Optional[Any]        =    BloomTokenizerFast
      A__	:			List[Any]        =    True
      A__	:			int        =    False
      A__	:			Any        =    '''tokenizer_file'''
      A__	:			Optional[int]        =    {'''bos_token''': '''<s>''', '''eos_token''': '''</s>''', '''unk_token''': '''<unk>''', '''pad_token''': '''<pad>'''}




      def 		snake_case_			(      self		:       Any				):
          super().setUp()
          __lowercase		:			int	    =       BloomTokenizerFast.from_pretrained('''bigscience/tokenizer'''				)
          tokenizer.save_pretrained(self.tmpdirname				)




      def 		snake_case_			(      self		:       Dict				,       **_snake_case		:       Any				):
          kwargs.update(self.special_tokens_map				)
          return BloomTokenizerFast.from_pretrained(self.tmpdirname				,       **_snake_case				)




      def 		snake_case_			(      self		:       Any				):
          __lowercase		:			Dict	    =       self.get_rust_tokenizer()

          __lowercase		:			Optional[int]	    =       ['''The quick brown fox</s>''', '''jumps over the lazy dog</s>''']
          __lowercase		:			Union[str, Any]	    =       [[2175, 2_3714, 7_3173, 14_4252, 2], [77, 13_2619, 3478, 368, 10_9586, 3_5433, 2]]

          __lowercase		:			Optional[int]	    =       tokenizer.batch_encode_plus(_snake_case				)['''input_ids''']
          self.assertListEqual(_snake_case				,       _snake_case				)

          __lowercase		:			List[Any]	    =       tokenizer.batch_decode(_snake_case				)
          self.assertListEqual(_snake_case				,       _snake_case				)




      def 		snake_case_			(      self		:       str				,       _snake_case		:       int=6				):
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'				):
                  __lowercase		:			Dict	    =       self.rust_tokenizer_class.from_pretrained(_snake_case				,       **_snake_case				)
                  # tokenizer_r.pad_token = None # Hotfixing padding = None
                  # Simple input
                  __lowercase		:			List[Any]	    =       '''This is a simple input'''
                  __lowercase		:			List[str]	    =       ['''This is a simple input 1''', '''This is a simple input 2''']
                  __lowercase		:			Optional[Any]	    =       ('''This is a simple input''', '''This is a pair''')
                  __lowercase		:			Any	    =       [
                      ('''This is a simple input 1''', '''This is a simple input 2'''),
                      ('''This is a simple pair 1''', '''This is a simple pair 2'''),
                  ]

                  # Simple input tests
                  try:
                      tokenizer_r.encode(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.encode_plus(_snake_case				,       max_length=_snake_case				)

                      tokenizer_r.batch_encode_plus(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.encode(_snake_case				,       max_length=_snake_case				)
                      tokenizer_r.batch_encode_plus(_snake_case				,       max_length=_snake_case				)
                  except ValueError:
                      self.fail('''Bloom Tokenizer should be able to deal with padding'''				)

                  __lowercase		:			Dict	    =       None  # Hotfixing padding = None
                  self.assertRaises(_snake_case				,       tokenizer_r.encode				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Simple input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Simple input
                  self.assertRaises(
                      _snake_case				,       tokenizer_r.batch_encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				,       )

                  # Pair input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Pair input
                  self.assertRaises(_snake_case				,       tokenizer_r.encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				)

                  # Pair input
                  self.assertRaises(
                      _snake_case				,       tokenizer_r.batch_encode_plus				,       _snake_case				,       max_length=_snake_case				,       padding='''max_length'''				,       )




      def 		snake_case_			(      self		:       Optional[int]				):
          __lowercase		:			List[Any]	    =       self.get_rust_tokenizer()
          __lowercase		:			int	    =       load_dataset('''xnli'''				,       '''all_languages'''				,       split='''test'''				,       streaming=_snake_case				)

          __lowercase		:			Optional[Any]	    =       next(iter(_snake_case				)				)['''premise''']  # pick up one data
          __lowercase		:			List[str]	    =       list(sample_data.values()				)

          __lowercase		:			List[str]	    =       list(map(tokenizer.encode				,       _snake_case				)				)
          __lowercase		:			Tuple	    =       [tokenizer.decode(_snake_case				,       clean_up_tokenization_spaces=_snake_case				) for x in output_tokens]
          self.assertListEqual(_snake_case				,       _snake_case				)




      def 		snake_case_			(      self		:       List[Any]				):
          # The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
          # any sequence length constraints. This test of the parent class will fail since it relies on the
          # maximum sequence length of the positoonal embeddings.
          self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map				)				,       1				)
          self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()				)[0]				)				,       1				)


