


import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


snake_case__			 =						logging.get_logger(__name__)

snake_case__			 =						{
    '''salesforce/blip2-opt-2.7b''': '''https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json''',
}


class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'blip_2_vision_model'




						def __init__(	self						:   Any   ,     __A						:   Any=1408   ,     __A						:   Union[str, Any]=6144   ,     __A						:   Dict=39   ,     __A						:   Union[str, Any]=16   ,     __A						:   Tuple=224   ,     __A						:   int=14   ,     __A						:   List[str]="gelu"   ,     __A						:   List[Any]=0.00_001   ,     __A						:   Any=0.0   ,     __A						:   List[Any]=1E-10   ,     __A						:   Optional[Any]=True   ,     **__A						:   Tuple   ,     )      ->Union[str, Any]:






									"""simple docstring"""






									super().__init__(**__A						)

									a__ :Union[str, Any]						  =    hidden_size
									a__ :int						  =    intermediate_size
									a__ :List[Any]						  =    num_hidden_layers
									a__ :Union[str, Any]						  =    num_attention_heads
									a__ :Optional[Any]						  =    patch_size
									a__ :Any						  =    image_size
									a__ :str						  =    initializer_range
									a__ :Tuple						  =    attention_dropout
									a__ :Union[str, Any]						  =    layer_norm_eps
									a__ :Any						  =    hidden_act
									a__ :List[str]						  =    qkv_bias






						@classmethod
						def  _snake_case					(	cls						:   List[Any]   ,     __A						:   Union[str, os.PathLike]   ,     **__A						:   Dict						)      ->"PretrainedConfig":






									"""simple docstring"""






									cls._set_token_in_kwargs(__A						)

									a__  ,  a__ :Tuple						  =    cls.get_config_dict(__A   ,     **__A						)

									# get the vision config dict if we are loading from Blip2Config
									if config_dict.get("model_type"						) == "blip-2":
												a__ :Optional[Any]						  =    config_dict["vision_config"]

									if "model_type" in config_dict and hasattr(cls   ,     "model_type"						) and config_dict["model_type"] != cls.model_type:
												logger.warning(
												    F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
												    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''						)

									return cls.from_dict(__A   ,     **__A						)






class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'blip_2_qformer'




						def __init__(	self						:   Dict   ,     __A						:   int=30522   ,     __A						:   str=768   ,     __A						:   List[Any]=12   ,     __A						:   Any=12   ,     __A						:   List[str]=3072   ,     __A						:   Union[str, Any]="gelu"   ,     __A						:   int=0.1   ,     __A						:   int=0.1   ,     __A						:   List[Any]=512   ,     __A						:   List[str]=0.02   ,     __A						:   Tuple=1E-12   ,     __A						:   Tuple=0   ,     __A						:   Any="absolute"   ,     __A						:   List[Any]=2   ,     __A						:   Union[str, Any]=1408   ,     **__A						:   List[Any]   ,     )      ->List[Any]:






									"""simple docstring"""






									super().__init__(pad_token_id=__A   ,     **__A						)

									a__ :Tuple						  =    vocab_size
									a__ :List[Any]						  =    hidden_size
									a__ :Tuple						  =    num_hidden_layers
									a__ :str						  =    num_attention_heads
									a__ :int						  =    hidden_act
									a__ :Optional[Any]						  =    intermediate_size
									a__ :int						  =    hidden_dropout_prob
									a__ :Union[str, Any]						  =    attention_probs_dropout_prob
									a__ :Optional[Any]						  =    max_position_embeddings
									a__ :Optional[int]						  =    initializer_range
									a__ :Union[str, Any]						  =    layer_norm_eps
									a__ :Optional[Any]						  =    position_embedding_type
									a__ :Any						  =    cross_attention_frequency
									a__ :List[str]						  =    encoder_hidden_size






						@classmethod
						def  _snake_case					(	cls						:   Optional[Any]   ,     __A						:   Union[str, os.PathLike]   ,     **__A						:   Union[str, Any]						)      ->"PretrainedConfig":






									"""simple docstring"""






									cls._set_token_in_kwargs(__A						)

									a__  ,  a__ :Optional[Any]						  =    cls.get_config_dict(__A   ,     **__A						)

									# get the qformer config dict if we are loading from Blip2Config
									if config_dict.get("model_type"						) == "blip-2":
												a__ :Tuple						  =    config_dict["qformer_config"]

									if "model_type" in config_dict and hasattr(cls   ,     "model_type"						) and config_dict["model_type"] != cls.model_type:
												logger.warning(
												    F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
												    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''						)

									return cls.from_dict(__A   ,     **__A						)






class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'blip-2'
						lowerCamelCase_         =     True




						def __init__(	self						:   Optional[Any]   ,     __A						:   List[str]=None   ,     __A						:   Tuple=None   ,     __A						:   Tuple=None   ,     __A						:   Tuple=32   ,     **__A						:   Optional[Any]						)      ->Dict:






									"""simple docstring"""






									super().__init__(**__A						)

									if vision_config is None:
												a__ :List[Any]						  =    {}
												logger.info("vision_config is None. initializing the Blip2VisionConfig with default values."						)

									if qformer_config is None:
												a__ :Optional[Any]						  =    {}
												logger.info("qformer_config is None. Initializing the Blip2QFormerConfig with default values."						)

									if text_config is None:
												a__ :Dict						  =    {}
												logger.info("text_config is None. Initializing the text config with default values (`OPTConfig`)."						)

									a__ :str						  =    BlipaVisionConfig(**__A						)
									a__ :int						  =    BlipaQFormerConfig(**__A						)
									a__ :Tuple						  =    text_config["model_type"] if "model_type" in text_config else "opt"
									a__ :Tuple						  =    CONFIG_MAPPING[text_model_type](**__A						)

									a__ :Tuple						  =    self.text_config.tie_word_embeddings
									a__ :Optional[int]						  =    self.text_config.is_encoder_decoder

									a__ :Any						  =    num_query_tokens
									a__ :Dict						  =    self.vision_config.hidden_size
									a__ :List[str]						  =    self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
									a__ :str						  =    1.0
									a__ :List[Any]						  =    0.02




						@classmethod
						def  _snake_case					(	cls						:   Any   ,     __A						:   BlipaVisionConfig   ,     __A						:   BlipaQFormerConfig   ,     __A						:   PretrainedConfig   ,     **__A						:   Any   ,     )      ->Any:






									"""simple docstring"""






									return cls(
									    vision_config=vision_config.to_dict()   ,     qformer_config=qformer_config.to_dict()   ,     text_config=text_config.to_dict()   ,     **__A   ,     )






						def  _snake_case					(	self						:   Tuple						)      ->Tuple:






									"""simple docstring"""






									a__ :Tuple						  =    copy.deepcopy(self.__dict__						)
									a__ :List[str]						  =    self.vision_config.to_dict()
									a__ :Dict						  =    self.qformer_config.to_dict()
									a__ :Dict						  =    self.text_config.to_dict()
									a__ :Union[str, Any]						  =    self.__class__.model_type
									return output






import sys
from collections import defaultdict


class 					lowerCAmelCase_ :




						def __init__(	self						:   Optional[int]						)      ->Any:






									"""simple docstring"""






									a__ :Optional[Any]						  =    []




						def  _snake_case					(	self						:   Optional[Any]   ,     __A						:   List[Any]						)      ->List[str]:






									"""simple docstring"""






									return self.node_position[vertex]




						def  _snake_case					(	self						:   Optional[Any]   ,     __A						:   str   ,     __A						:   Any						)      ->Dict:






									"""simple docstring"""






									a__ :Dict						  =    pos




						def  _snake_case					(	self						:   str   ,     __A						:   Union[str, Any]   ,     __A						:   Union[str, Any]   ,     __A						:   Optional[Any]   ,     __A						:   Optional[int]						)      ->List[Any]:






									"""simple docstring"""






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

															a__ :Any						  =    self.get_position(positions[smallest_child]						)
															self.set_position(
															    positions[smallest_child]   ,     self.get_position(positions[start]						)						)
															self.set_position(positions[start]   ,     __A						)

															self.top_to_bottom(__A   ,     __A   ,     __A   ,     __A						)




						def  _snake_case					(	self						:   List[str]   ,     __A						:   Any   ,     __A						:   List[str]   ,     __A						:   Any   ,     __A						:   str						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Optional[Any]						  =    position[index]

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

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




						def  _snake_case					(	self						:   Tuple   ,     __A						:   int   ,     __A						:   int						)      ->Union[str, Any]:






									"""simple docstring"""






									a__ :Tuple						  =    len(__A						) // 2 - 1
									for i in range(__A   ,     -1   ,     -1						):
												self.top_to_bottom(__A   ,     __A   ,     len(__A						)   ,     __A						)






						def  _snake_case					(	self						:   List[Any]   ,     __A						:   List[Any]   ,     __A						:   int						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Any						  =    positions[0]
									a__ :str						  =    sys.maxsize
									self.top_to_bottom(__A   ,     0   ,     len(__A						)   ,     __A						)
									return temp






def 				lowerCamelCase__	(      a	:   Any				)    ->	Union[str, Any]:





			"""simple docstring"""
			a__ :Tuple						  =    Heap()

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

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

			a__ :Tuple						  =    []
			a__ :Any						  =    1
			a__ :int						  =    sys.maxsize
			for neighbor, distance in adjacency_list[0]:
						a__ :int						  =    0
						a__ :List[str]						  =    distance
			heap.heapify(a	,  a				)

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


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


