
"""simple docstring"""


import json
import os
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import ImageGPTImageProcessor







class 				lowerCAmelCase_				(      unittest.TestCase    ):



						'''simple docstring'''


						def __init__( self     :      int  ,A_     :      Tuple  ,A_     :      str=7  ,A_     :      Tuple=3  ,A_     :      List[Any]=18  ,A_     :      List[str]=30  ,A_     :      Optional[Any]=400  ,A_     :      Any=True  ,A_     :      Optional[Any]=None  ,A_     :      List[str]=True  ,)     ->   str:
							A						   =   size if size is not None else {'height': 18, 'width': 18}
							A						   =   parent
							A						   =   batch_size
							A						   =   num_channels
							A						   =   image_size
							A						   =   min_resolution
							A						   =   max_resolution
							A						   =   do_resize
							A						   =   size
							A						   =   do_normalize




						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   List[Any]:
							return {
							    # here we create 2 clusters for the sake of simplicity
							    "clusters": np.asarray(
							        [
							            [0.88_66_44_36_34_03_32_03, 0.66_18_82_93_69_54_49_83, 0.38_91_74_64_01_78_68_04],
							            [-0.60_42_55_91_46_88_11_04, -0.0_22_95_00_88_60_52_84_69, 0.54_23_79_73_69_00_32_96],
							        ]      ),
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_normalize": self.do_normalize,
							}







@require_torch
@require_vision
class 				lowerCAmelCase_				(      _lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    List[Any]      =    ImageGPTImageProcessor if is_vision_available() else None


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   Any:
							A						   =   ImageGPTImageProcessingTester(self      )


						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Union[str, Any]:
							return self.image_processor_tester.prepare_image_processor_dict()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   List[Any]:
							A						   =   self.image_processing_class(**self.image_processor_dict      )
							self.assertTrue(hasattr(A_  ,'clusters'      )      )
							self.assertTrue(hasattr(A_  ,'do_resize'      )      )
							self.assertTrue(hasattr(A_  ,'size'      )      )
							self.assertTrue(hasattr(A_  ,'do_normalize'      )      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Tuple:
							A						   =   self.image_processing_class.from_dict(self.image_processor_dict      )
							self.assertEqual(image_processor.size  ,{'height': 18, 'width': 18}      )

							A						   =   self.image_processing_class.from_dict(self.image_processor_dict  ,size=42      )
							self.assertEqual(image_processor.size  ,{'height': 42, 'width': 42}      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   str:
							A						   =   self.image_processing_class(**self.image_processor_dict      )
							A						   =   json.loads(image_processor.to_json_string()      )
							for key, value in self.image_processor_dict.items():
								if key == "clusters":
									self.assertTrue(np.array_equal(A_  ,obj[key]      )      )
								else:
									self.assertEqual(obj[key]  ,A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   Union[str, Any]:
							A						   =   self.image_processing_class(**self.image_processor_dict      )

							with tempfile.TemporaryDirectory() as tmpdirname:
								A						   =   os.path.join(A_  ,'image_processor.json'      )
								image_processor_first.to_json_file(A_      )
								A						   =   self.image_processing_class.from_json_file(A_      ).to_dict()

							A						   =   image_processor_first.to_dict()
							for key, value in image_processor_first.items():
								if key == "clusters":
									self.assertTrue(np.array_equal(A_  ,image_processor_second[key]      )      )
								else:
									self.assertEqual(image_processor_first[key]  ,A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   int:
							A						   =   self.image_processing_class(**self.image_processor_dict      )

							with tempfile.TemporaryDirectory() as tmpdirname:
								image_processor_first.save_pretrained(A_      )
								A						   =   self.image_processing_class.from_pretrained(A_      ).to_dict()

							A						   =   image_processor_first.to_dict()
							for key, value in image_processor_first.items():
								if key == "clusters":
									self.assertTrue(np.array_equal(A_  ,image_processor_second[key]      )      )
								else:
									self.assertEqual(image_processor_first[key]  ,A_      )




						@unittest.skip('ImageGPT requires clusters at initialization'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Union[str, Any]:
							pass






def       _snake_case				(		):
	A						   =   load_dataset('hf-internal-testing/fixtures_image_utils'	,      split='test'     )

	A						   =   Image.open(dataset[4]['file']     )
	A						   =   Image.open(dataset[5]['file']     )

	A						   =   [imagea, imagea]

	return images







@require_vision
@require_torch
class 				lowerCAmelCase_				(      unittest.TestCase    ):



						'''simple docstring'''


						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   int:
							A						   =   ImageGPTImageProcessor.from_pretrained('openai/imagegpt-small'      )

							A						   =   prepare_images()

							# test non-batched
							A						   =   image_processing(images[0]  ,return_tensors='pt'      )

							self.assertIsInstance(encoding.input_ids  ,torch.LongTensor      )
							self.assertEqual(encoding.input_ids.shape  ,(1, 1024)      )

							A						   =   [306, 191, 191]
							self.assertEqual(encoding.input_ids[0, :3].tolist()  ,A_      )

							# test batched
							A						   =   image_processing(A_  ,return_tensors='pt'      )

							self.assertIsInstance(encoding.input_ids  ,torch.LongTensor      )
							self.assertEqual(encoding.input_ids.shape  ,(2, 1024)      )

							A						   =   [303, 13, 13]
							self.assertEqual(encoding.input_ids[1, -3:].tolist()  ,A_      )

"""simple docstring"""


import sys
from collections import defaultdict







class 				lowerCAmelCase_				:



						'''simple docstring'''


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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      int      )     ->   Optional[int]:
							return self.node_position[vertex]


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      List[Any]  ,A_     :      Any      )     ->   List[Any]:
							A						   =   pos


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      str  ,A_     :      str  ,A_     :      Dict  ,A_     :      List[str]      )     ->   str:
							if start > size // 2 - 1:
								return
							else:
								if 2 * start + 2 >= size:
									A						   =   2 * start + 1
								else:
									if heap[2 * start + 1] < heap[2 * start + 2]:
										A						   =   2 * start + 1
									else:
										A						   =   2 * start + 2
								if heap[smallest_child] < heap[start]:
									A   ,      A						   =   heap[smallest_child], positions[smallest_child]
									A   ,      A						   =   (
									    heap[start],
									    positions[start],
									)
									A   ,      A						   =   temp, tempa

									A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      Optional[int]  ,A_     :      Dict  ,A_     :      str  ,A_     :      Union[str, Any]      )     ->   Dict:
							A						   =   position[index]

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      Tuple  ,A_     :      Dict      )     ->   Union[str, Any]:
							A						   =   len(A_      ) // 2 - 1
							for i in range(A_  ,-1  ,-1      ):
								self.top_to_bottom(A_  ,A_  ,len(A_      )  ,A_      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Optional[int]  ,A_     :      Dict      )     ->   Union[str, Any]:
							A						   =   positions[0]
							A						   =   sys.maxsize
							self.top_to_bottom(A_  ,0  ,len(A_      )  ,A_      )
							return temp






def       _snake_case				(		snake_case__   :     Dict     ):
	A						   =   Heap()

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

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

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

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


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