


import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from requests.exceptions import HTTPError

from transformers import AutoFeatureExtractor, WavaVecaFeatureExtractor
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test


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

from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


snake_case__			 =						get_tests_dir('''fixtures''')


class 					lowerCAmelCase_ (       unittest.TestCase):




						def  _snake_case					(	self						:   Tuple						)      ->Tuple:






									"""simple docstring"""






									a__ :str						  =    mock.Mock()
									a__ :Optional[Any]						  =    500
									a__ :Any						  =    {}
									a__ :int						  =    HTTPError
									a__ :str						  =    {}

									# Download this model to make sure it's in the cache.
									a__ :List[Any]						  =    WavaVecaFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-wav2vec2"						)
									# Under the mock environment we get a 500 error when trying to reach the model.
									with mock.patch("requests.Session.request"   ,     return_value=__A						) as mock_head:
												a__ :Union[str, Any]						  =    WavaVecaFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-wav2vec2"						)
												# This check we did call the fake head request
												mock_head.assert_called()






						def  _snake_case					(	self						:   Tuple						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Tuple						  =    WavaVecaFeatureExtractor.from_pretrained(
									    "https://huggingface.co/hf-internal-testing/tiny-random-wav2vec2/resolve/main/preprocessor_config.json"						)






@is_staging_test
class 					lowerCAmelCase_ (       unittest.TestCase):




						@classmethod
						def  _snake_case					(	cls						:   Optional[int]						)      ->List[str]:






									"""simple docstring"""






									a__ :str						  =    TOKEN
									HfFolder.save_token(__A						)




						@classmethod
						def  _snake_case					(	cls						:   int						)      ->Optional[Any]:






									"""simple docstring"""






									try:
												delete_repo(token=cls._token   ,     repo_id="test-feature-extractor"						)
									except HTTPError:
												pass

									try:
												delete_repo(token=cls._token   ,     repo_id="valid_org/test-feature-extractor-org"						)
									except HTTPError:
												pass

									try:
												delete_repo(token=cls._token   ,     repo_id="test-dynamic-feature-extractor"						)
									except HTTPError:
												pass




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






									"""simple docstring"""






									a__ :Tuple						  =    WavaVecaFeatureExtractor.from_pretrained(__A						)
									feature_extractor.push_to_hub("test-feature-extractor"   ,     use_auth_token=self._token						)

									a__ :Union[str, Any]						  =    WavaVecaFeatureExtractor.from_pretrained(F'''{USER}/test-feature-extractor'''						)
									for k, v in feature_extractor.__dict__.items():
												self.assertEqual(__A   ,     getattr(__A   ,     __A						)						)

									# Reset repo
									delete_repo(token=self._token   ,     repo_id="test-feature-extractor"						)

									# Push to hub via save_pretrained
									with tempfile.TemporaryDirectory() as tmp_dir:
												feature_extractor.save_pretrained(
												    __A   ,     repo_id="test-feature-extractor"   ,     push_to_hub=__A   ,     use_auth_token=self._token						)

									a__ :Optional[Any]						  =    WavaVecaFeatureExtractor.from_pretrained(F'''{USER}/test-feature-extractor'''						)
									for k, v in feature_extractor.__dict__.items():
												self.assertEqual(__A   ,     getattr(__A   ,     __A						)						)




						def  _snake_case					(	self						:   Dict						)      ->str:






									"""simple docstring"""






									a__ :List[Any]						  =    WavaVecaFeatureExtractor.from_pretrained(__A						)
									feature_extractor.push_to_hub("valid_org/test-feature-extractor"   ,     use_auth_token=self._token						)

									a__ :str						  =    WavaVecaFeatureExtractor.from_pretrained("valid_org/test-feature-extractor"						)
									for k, v in feature_extractor.__dict__.items():
												self.assertEqual(__A   ,     getattr(__A   ,     __A						)						)

									# Reset repo
									delete_repo(token=self._token   ,     repo_id="valid_org/test-feature-extractor"						)

									# Push to hub via save_pretrained
									with tempfile.TemporaryDirectory() as tmp_dir:
												feature_extractor.save_pretrained(
												    __A   ,     repo_id="valid_org/test-feature-extractor-org"   ,     push_to_hub=__A   ,     use_auth_token=self._token						)

									a__ :int						  =    WavaVecaFeatureExtractor.from_pretrained("valid_org/test-feature-extractor-org"						)
									for k, v in feature_extractor.__dict__.items():
												self.assertEqual(__A   ,     getattr(__A   ,     __A						)						)






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






									"""simple docstring"""






									CustomFeatureExtractor.register_for_auto_class()
									a__ :Dict						  =    CustomFeatureExtractor.from_pretrained(__A						)

									feature_extractor.push_to_hub("test-dynamic-feature-extractor"   ,     use_auth_token=self._token						)

									# This has added the proper auto_map field to the config
									self.assertDictEqual(
									    feature_extractor.auto_map   ,     {"AutoFeatureExtractor": "custom_feature_extraction.CustomFeatureExtractor"}   ,     )

									a__ :str						  =    AutoFeatureExtractor.from_pretrained(
									    F'''{USER}/test-dynamic-feature-extractor'''   ,     trust_remote_code=__A						)
									# Can't make an isinstance check because the new_feature_extractor is from the CustomFeatureExtractor class of a dynamic module
									self.assertEqual(new_feature_extractor.__class__.__name__   ,     "CustomFeatureExtractor"						)






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


