
import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402


UpperCAmelCase	      = get_tests_dir('''fixtures/dummy-config.json''')







class        A_   (			unittest.TestCase   ):




	'''simple docstring'''


	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    0





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		self.assertIsNotNone(transformers.models.auto.__spec__       )
		self.assertIsNotNone(importlib.util.find_spec('transformers.models.auto'       )       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    AutoConfig.from_pretrained('bert-base-uncased'       )
		self.assertIsInstance(snake_case		,    snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    AutoConfig.from_pretrained(snake_case       )
		self.assertIsInstance(snake_case		,    snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    AutoConfig.from_pretrained(snake_case       )
		self.assertIsInstance(snake_case		,    snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    AutoConfig.for_model('roberta'       )
		self.assertIsInstance(snake_case		,    snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		with tempfile.TemporaryDirectory() as tmp_dir:
			# This model name contains bert and roberta, but roberta ends up being picked.
			lowercase       =    os.path.join(snake_case		,    'fake-roberta'       )
			os.makedirs(snake_case		,    exist_ok=snake_case       )
			with open(os.path.join(snake_case		,    'config.json'       )		,    'w'       ) as f:
				f.write(json.dumps({}       )       )
			lowercase       =    AutoConfig.from_pretrained(snake_case       )
			self.assertEqual(type(snake_case       )		,    snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		try:
			AutoConfig.register('custom'		,    snake_case       )
			# Wrong model type will raise an error
			with self.assertRaises(snake_case       ):
				AutoConfig.register('model'		,    snake_case       )
			# Trying to register something existing in the Transformers library will raise an error
			with self.assertRaises(snake_case       ):
				AutoConfig.register('bert'		,    snake_case       )

			# Now that the config is registered, it can be used as any other config with the auto-API
			lowercase       =    CustomConfig()
			with tempfile.TemporaryDirectory() as tmp_dir:
				config.save_pretrained(snake_case       )
				lowercase       =    AutoConfig.from_pretrained(snake_case       )
				self.assertIsInstance(snake_case		,    snake_case       )

		finally:
			if "custom" in CONFIG_MAPPING._extra_content:
				del CONFIG_MAPPING._extra_content["custom"]





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		with self.assertRaisesRegex(
		    snake_case		,    'bert-base is not a local folder and is not a valid model identifier'       ):
			lowercase       =    AutoConfig.from_pretrained('bert-base'       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		with self.assertRaisesRegex(
		    snake_case		,    r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'       ):
			lowercase       =    AutoConfig.from_pretrained(snake_case		,    revision='aaaaaa'       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		with self.assertRaisesRegex(
		    snake_case		,    'hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.'		,    ):
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/no-config-test-repo'       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# If remote code is not set, we will time out when asking whether to load the model.
		with self.assertRaises(snake_case       ):
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'       )
		# If remote code is disabled, we can't load this config.
		with self.assertRaises(snake_case       ):
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,    trust_remote_code=snake_case       )

		lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,    trust_remote_code=snake_case       )
		self.assertEqual(config.__class__.__name__		,    'NewModelConfig'       )

		# Test config can be reloaded.
		with tempfile.TemporaryDirectory() as tmp_dir:
			config.save_pretrained(snake_case       )
			lowercase       =    AutoConfig.from_pretrained(snake_case		,    trust_remote_code=snake_case       )
		self.assertEqual(reloaded_config.__class__.__name__		,    'NewModelConfig'       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):







		class        A_   (			__lowerCamelCase   ):




			'''simple docstring'''


			_UpperCamelCase     :     List[str]							 =       """new-model"""

		try:
			AutoConfig.register('new-model'		,    snake_case       )
			# If remote code is not set, the default is to use local
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'       )
			self.assertEqual(config.__class__.__name__		,    'NewModelConfigLocal'       )

			# If remote code is disabled, we load the local one.
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,    trust_remote_code=snake_case       )
			self.assertEqual(config.__class__.__name__		,    'NewModelConfigLocal'       )

			# If remote is enabled, we load from the Hub
			lowercase       =    AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,    trust_remote_code=snake_case       )
			self.assertEqual(config.__class__.__name__		,    'NewModelConfig'       )

		finally:
			if "new-model" in CONFIG_MAPPING._extra_content:
				del CONFIG_MAPPING._extra_content["new-model"]



import sys
from collections import defaultdict







class        A_   :




	'''simple docstring'''


	def __init__(       self       ):
		lowercase       =    []





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





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case       ):
		lowercase       =    pos





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

				lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case		,    snake_case		,    snake_case       ):
		lowercase       =    position[index]

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

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





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case       ):
		lowercase       =    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 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case       ):
		lowercase       =    positions[0]
		lowercase       =    sys.maxsize
		self.top_to_bottom(snake_case		,    0		,    len(snake_case       )		,    snake_case       )
		return temp






def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE							):
	lowercase       =    Heap()

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

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

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

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


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

