


import os
import time
import warnings
from dataclasses import dataclass, field
from enum import Enum
from typing import List, Optional, Union

import torch
from filelock import FileLock
from torch.utils.data import Dataset

from ...tokenization_utils_base import PreTrainedTokenizerBase
from ...utils import logging
from ..processors.glue import glue_convert_examples_to_features, glue_output_modes, glue_processors
from ..processors.utils import InputFeatures


snake_case__			 =						logging.get_logger(__name__)


@dataclass
class 					lowerCAmelCase_ :
						lowerCamelCase_         =     field(metadata={'help': 'The name of the task to train on: ' + ', '.join(glue_processors.keys())})
						lowerCamelCase_         =     field(
						    metadata={'help': 'The input data dir. Should contain the .tsv files (or other data files) for the task.'})
						lowerCamelCase_         =     field(
						    default=128			,metadata={
						        'help': (
						            'The maximum total input sequence length after tokenization. Sequences longer '
						            'than this will be truncated, sequences shorter will be padded.'
						        )
						    }			,)
						lowerCamelCase_         =     field(
						    default=_a			,metadata={'help': 'Overwrite the cached training and evaluation sets'})




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






									"""simple docstring"""






									a__ :int						  =    self.task_name.lower()






class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'train'
						lowerCamelCase_         =     'dev'
						lowerCamelCase_         =     'test'






class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     42
						lowerCamelCase_         =     42
						lowerCamelCase_         =     42




						def __init__(	self						:   List[str]   ,     __A						:   GlueDataTrainingArguments   ,     __A						:   PreTrainedTokenizerBase   ,     __A						:   Optional[int] = None   ,     __A						:   Union[str, Split] = Split.train   ,     __A						:   Optional[str] = None   ,     )      ->Tuple:






									"""simple docstring"""






									warnings.warn(
									    "This dataset will be removed from the library soon, preprocessing should be handled with the 🤗 Datasets "
									    "library. You can have a look at this example script for pointers: "
									    "https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py"   ,     __A   ,     )
									a__ :List[Any]						  =    args
									a__ :Optional[int]						  =    glue_processors[args.task_name]()
									a__ :Any						  =    glue_output_modes[args.task_name]
									if isinstance(__A   ,     __A						):
												try:
															a__ :Tuple						  =    Split[mode]
												except KeyError:
															raise KeyError("mode is not a valid split name"						)
        # Load data features from cache or dataset file
									a__ :int						  =    os.path.join(
									    cache_dir if cache_dir is not None else args.data_dir   ,     F'''cached_{mode.value}_{tokenizer.__class__.__name__}_{args.max_seq_length}_{args.task_name}'''   ,     )
									a__ :List[Any]						  =    self.processor.get_labels()
									if args.task_name in ["mnli", "mnli-mm"] and tokenizer.__class__.__name__ in (
									    "RobertaTokenizer",
									    "RobertaTokenizerFast",
									    "XLMRobertaTokenizer",
									    "BartTokenizer",
									    "BartTokenizerFast",
									):
												# HACK(label indices are swapped in RoBERTa pretrained model)
												a__  ,  a__ :Dict						  =    label_list[2], label_list[1]
									a__ :str						  =    label_list

									# Make sure only the first process in distributed training processes the dataset,
									# and the others will use the cache.
									a__ :str						  =    cached_features_file + ".lock"
									with FileLock(__A						):
												if os.path.exists(__A						) and not args.overwrite_cache:
															a__ :Tuple						  =    time.time()
															a__ :Optional[int]						  =    torch.load(__A						)
															logger.info(
															    F'''Loading features from cached file {cached_features_file} [took %.3f s]'''   ,     time.time() - start						)
												else:
															logger.info(F'''Creating features from dataset file at {args.data_dir}'''						)

															if mode == Split.dev:
																		a__ :List[str]						  =    self.processor.get_dev_examples(args.data_dir						)
															elif mode == Split.test:
																		a__ :int						  =    self.processor.get_test_examples(args.data_dir						)
															else:
																		a__ :Tuple						  =    self.processor.get_train_examples(args.data_dir						)
															if limit_length is not None:
																		a__ :Optional[int]						  =    examples[:limit_length]
															a__ :List[str]						  =    glue_convert_examples_to_features(
															    __A   ,     __A   ,     max_length=args.max_seq_length   ,     label_list=__A   ,     output_mode=self.output_mode   ,     )
															a__ :Optional[Any]						  =    time.time()
															torch.save(self.features   ,     __A						)
															# ^ This seems to take a lot of time so I want to investigate why and how we can improve.
															logger.info(
															    F'''Saving features into cached file {cached_features_file} [took {time.time() - start:.3f} s]'''						)




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






									"""simple docstring"""






									return len(self.features						)




						def __getitem__(	self						:   str   ,     __A						:   str						)      ->InputFeatures:






									"""simple docstring"""






									return self.features[i]






						def  _snake_case					(	self						:   Tuple						)      ->Dict:






									"""simple docstring"""






									return self.label_list






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))


