




from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


UpperCamelCase__    			=			logging.get_logger(__name__)

UpperCamelCase__    			=			{
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}
class 			a__    (					snake_case__      ):
						_a							:    List[str]					=    """marian"""
						_a							:    Optional[int]					=    ["""past_key_values"""]
						_a							:    List[str]					=    {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






						def __init__(   self		,			_A=5_8_1_0_1		,			_A=None		,			_A=1_0_2_4		,			_A=1_2		,			_A=4_0_9_6		,			_A=1_6		,			_A=1_2		,			_A=4_0_9_6		,			_A=1_6		,			_A=0.0		,			_A=0.0		,			_A=True		,			_A=True		,			_A="gelu"		,			_A=1_0_2_4		,			_A=0.1		,			_A=0.0		,			_A=0.0		,			_A=0.02		,			_A=5_8_1_0_0		,			_A=False		,			_A=5_8_1_0_0		,			_A=0		,			_A=0		,			_A=True		,			**_A		,			):




											"""simple docstring"""



											__lowerCAmelCase				   =       vocab_size
											__lowerCAmelCase				   =       decoder_vocab_size or vocab_size
											__lowerCAmelCase				   =       max_position_embeddings
											__lowerCAmelCase				   =       d_model
											__lowerCAmelCase				   =       encoder_ffn_dim
											__lowerCAmelCase				   =       encoder_layers
											__lowerCAmelCase				   =       encoder_attention_heads
											__lowerCAmelCase				   =       decoder_ffn_dim
											__lowerCAmelCase				   =       decoder_layers
											__lowerCAmelCase				   =       decoder_attention_heads
											__lowerCAmelCase				   =       dropout
											__lowerCAmelCase				   =       attention_dropout
											__lowerCAmelCase				   =       activation_dropout
											__lowerCAmelCase				   =       activation_function
											__lowerCAmelCase				   =       init_std
											__lowerCAmelCase				   =       encoder_layerdrop
											__lowerCAmelCase				   =       decoder_layerdrop
											__lowerCAmelCase				   =       use_cache
											__lowerCAmelCase				   =       encoder_layers
											__lowerCAmelCase				   =       scale_embedding  # scale factor will be sqrt(d_model) if True
											__lowerCAmelCase				   =       share_encoder_decoder_embeddings
											super().__init__(
											    pad_token_id=_A		,			eos_token_id=_A		,			is_encoder_decoder=_A		,			decoder_start_token_id=_A		,			forced_eos_token_id=_A		,			**_A		,			)






class 			a__    (					snake_case__      ):






						@property
						# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
						def 				__SCREAMING_SNAKE_CASE(   self			):




											"""simple docstring"""



											if self.task in ["default", "seq2seq-lm"]:
																__lowerCAmelCase				   =       OrderedDict(
																    [
																        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																    ]			)

																if self.use_past:
																					__lowerCAmelCase				   =       {0: "batch"}
																					__lowerCAmelCase				   =       {0: "batch", 1: "past_decoder_sequence + sequence"}
																else:
																					__lowerCAmelCase				   =       {0: "batch", 1: "decoder_sequence"}
																					__lowerCAmelCase				   =       {0: "batch", 1: "decoder_sequence"}

																if self.use_past:
																					self.fill_with_past_key_values_(_A		,			direction="inputs"			)
											elif self.task == "causal-lm":
																# TODO: figure this case out.
																__lowerCAmelCase				   =       OrderedDict(
																    [
																        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																    ]			)
																if self.use_past:
																					__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_layers
																					for i in range(_A			):
																										__lowerCAmelCase				   =       {0: "batch", 2: "past_sequence + sequence"}
																										__lowerCAmelCase				   =       {0: "batch", 2: "past_sequence + sequence"}
											else:
																__lowerCAmelCase				   =       OrderedDict(
																    [
																        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																        ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
																        ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
																    ]			)

											return common_inputs






						@property
						# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
						def 				__SCREAMING_SNAKE_CASE(   self			):




											"""simple docstring"""



											if self.task in ["default", "seq2seq-lm"]:
																__lowerCAmelCase				   =       super().outputs
											else:
																__lowerCAmelCase				   =       super(_A		,			self			).outputs
																if self.use_past:
																					__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_layers
																					for i in range(_A			):
																										__lowerCAmelCase				   =       {0: "batch", 2: "past_sequence + sequence"}
																										__lowerCAmelCase				   =       {0: "batch", 2: "past_sequence + sequence"}
											return common_outputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A = -1		,			_A = -1		,			_A = False		,			_A = None		,			):




											"""simple docstring"""



											__lowerCAmelCase				   =       self._generate_dummy_inputs_for_encoder_and_decoder(
											    _A		,			_A		,			_A		,			_A		,			_A			)

											# Generate decoder inputs
											__lowerCAmelCase				   =       seq_length if not self.use_past else 1
											__lowerCAmelCase				   =       self._generate_dummy_inputs_for_encoder_and_decoder(
											    _A		,			_A		,			_A		,			_A		,			_A			)
											__lowerCAmelCase				   =       {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
											__lowerCAmelCase				   =       dict(**_A		,			**_A			)

											if self.use_past:
																if not is_torch_available():
																					raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."			)
																else:
																					import torch
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       common_inputs["input_ids"].shape
																__lowerCAmelCase				   =       common_inputs["decoder_input_ids"].shape[1]
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_attention_heads
																__lowerCAmelCase				   =       (
																    batch,
																    num_encoder_attention_heads,
																    encoder_seq_length,
																    self._config.hidden_size // num_encoder_attention_heads,
																)
																__lowerCAmelCase				   =       decoder_seq_length + 3
																__lowerCAmelCase				   =       (
																    batch,
																    num_decoder_attention_heads,
																    decoder_past_length,
																    self._config.hidden_size // num_decoder_attention_heads,
																)

																__lowerCAmelCase				   =       torch.cat(
																    [common_inputs["decoder_attention_mask"], torch.ones(_A		,			_A			)]		,			dim=1			)

																__lowerCAmelCase				   =       []
																# If the number of encoder and decoder layers are present in the model configuration, both are considered
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_layers
																__lowerCAmelCase				   =       min(_A		,			_A			)
																__lowerCAmelCase				   =       max(_A		,			_A			) - min_num_layers
																__lowerCAmelCase				   =       "encoder" if num_encoder_layers > num_decoder_layers else "decoder"

																for _ in range(_A			):
																					common_inputs["past_key_values"].append(
																					    (
																					        torch.zeros(_A			),
																					        torch.zeros(_A			),
																					        torch.zeros(_A			),
																					        torch.zeros(_A			),
																					    )			)
																# TODO: test this.
																__lowerCAmelCase				   =       encoder_shape if remaining_side_name == "encoder" else decoder_shape
																for _ in range(_A		,			_A			):
																					common_inputs["past_key_values"].append((torch.zeros(_A			), torch.zeros(_A			))			)
											return common_inputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A = -1		,			_A = -1		,			_A = False		,			_A = None		,			):




											"""simple docstring"""



											__lowerCAmelCase				   =       self._generate_dummy_inputs_for_encoder_and_decoder(
											    _A		,			_A		,			_A		,			_A		,			_A			)

											if self.use_past:
																if not is_torch_available():
																					raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."			)
																else:
																					import torch
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       common_inputs["input_ids"].shape
																# Not using the same length for past_key_values
																__lowerCAmelCase				   =       seqlen + 2
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_layers
																__lowerCAmelCase   ,							__lowerCAmelCase				   =       self.num_attention_heads
																__lowerCAmelCase				   =       (
																    batch,
																    num_encoder_attention_heads,
																    past_key_values_length,
																    self._config.hidden_size // num_encoder_attention_heads,
																)

																__lowerCAmelCase				   =       common_inputs["attention_mask"].dtype
																__lowerCAmelCase				   =       torch.cat(
																    [common_inputs["attention_mask"], torch.ones(_A		,			_A		,			dtype=_A			)]		,			dim=1			)
																__lowerCAmelCase				   =       [
																    (torch.zeros(_A			), torch.zeros(_A			)) for _ in range(_A			)
																]
											return common_inputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A = -1		,			_A = -1		,			_A = False		,			_A = None		,			):




											"""simple docstring"""



											__lowerCAmelCase				   =       compute_effective_axis_dimension(
											    _A		,			fixed_dimension=OnnxConfig.default_fixed_batch		,			num_token_to_add=0			)

											# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
											__lowerCAmelCase				   =       tokenizer.num_special_tokens_to_add(_A			)
											__lowerCAmelCase				   =       compute_effective_axis_dimension(
											    _A		,			fixed_dimension=OnnxConfig.default_fixed_sequence		,			num_token_to_add=_A			)

											# Generate dummy inputs according to compute batch and sequence
											__lowerCAmelCase				   =       [" ".join([tokenizer.unk_token]			) * seq_length] * batch_size
											__lowerCAmelCase				   =       dict(tokenizer(_A		,			return_tensors=_A			)			)
											return common_inputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A = -1		,			_A = -1		,			_A = False		,			_A = None		,			):




											"""simple docstring"""



											if self.task in ["default", "seq2seq-lm"]:
																__lowerCAmelCase				   =       self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																    _A		,			batch_size=_A		,			seq_length=_A		,			is_pair=_A		,			framework=_A			)

											else:
																__lowerCAmelCase				   =       self._generate_dummy_inputs_for_causal_lm(
																    _A		,			batch_size=_A		,			seq_length=_A		,			is_pair=_A		,			framework=_A			)

											return common_inputs






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A		,			_A		,			_A			):




											"""simple docstring"""



											if self.task in ["default", "seq2seq-lm"]:
																__lowerCAmelCase				   =       super()._flatten_past_key_values_(_A		,			_A		,			_A		,			_A			)
											else:
																__lowerCAmelCase				   =       super(_A		,			self			)._flatten_past_key_values_(
																    _A		,			_A		,			_A		,			_A			)






						@property
						def 				__SCREAMING_SNAKE_CASE(   self			):




											"""simple docstring"""



											return 1E-4








"""simple docstring"""


import sys
from collections import defaultdict
class   _UpperCamelCase  :
							'''simple docstring'''







							def __init__(     self	):
										__lowerCAmelCase				    =			[]

							def 			snake_case				(     self    ,   __a	):
										return self.node_position[vertex]

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			pos

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

																__lowerCAmelCase				    =			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    ,   __a    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			position[index]

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

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

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			len(__a	) // 2 - 1
										for i in range(__a    ,   -1    ,   -1	):
													self.top_to_bottom(__a    ,   __a    ,   len(__a	)    ,   __a	)



							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			positions[0]
										__lowerCAmelCase				    =			sys.maxsize
										self.top_to_bottom(__a    ,   0    ,   len(__a	)    ,   __a	)
										return temp


def _lowerCamelCase	(		_UpperCamelCase      ):

			'''simple docstring'''




			__lowerCAmelCase				    =			Heap()

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

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

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

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


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




