


import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin







@skip_mps
class 			_lowercase (							__lowerCamelCase							,  __lowerCamelCase							,  unittest.TestCase):


       """simple docstring"""




       A__											=			IFInpaintingSuperResolutionPipeline
       A__											=			TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
       A__											=			TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"original_image"})
       A__											=			PipelineTesterMixin.required_optional_params - {"""latents"""}





       def 						lowerCAmelCase     (   self							:			int       ):


             '''simple docstring'''



             return self._get_superresolution_dummy_components()





       def 						lowerCAmelCase     (   self							:			Union[str, Any]					,      __lowerCamelCase							:			Optional[int]					,      __lowerCamelCase							:			Dict=0       ):


             '''simple docstring'''



             if str(__lowerCamelCase       ).startswith("mps"       ):
                   lowerCamelCase__		:				int    =  torch.manual_seed(__lowerCamelCase       )
             else:
                   lowerCamelCase__		:				List[str]    =  torch.Generator(device=__lowerCamelCase       ).manual_seed(__lowerCamelCase       )

             lowerCamelCase__		:				Optional[Any]    =  floats_tensor((1, 3, 16, 16)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )
             lowerCamelCase__		:				Dict    =  floats_tensor((1, 3, 32, 32)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )
             lowerCamelCase__		:				List[Any]    =  floats_tensor((1, 3, 32, 32)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )

             lowerCamelCase__		:				Any    =  {
                 "prompt": "A painting of a squirrel eating a burger",
                 "image": image,
                 "original_image": original_image,
                 "mask_image": mask_image,
                 "generator": generator,
                 "num_inference_steps": 2,
                 "output_type": "numpy",
             }

             return inputs





       @unittest.skipIf(
           torch_device != "cuda" or not is_xformers_available()					,      reason="XFormers attention is only available with CUDA and `xformers` installed"					,      )
       def 						lowerCAmelCase     (   self							:			Tuple       ):


             '''simple docstring'''



             self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3       )





       def 						lowerCAmelCase     (   self							:			Optional[Any]       ):


             '''simple docstring'''



             self._test_save_load_optional_components()





       @unittest.skipIf(torch_device != "cuda"					,      reason="float16 requires CUDA"       )
       def 						lowerCAmelCase     (   self							:			Tuple       ):


             '''simple docstring'''



             super().test_save_load_floataa(expected_max_diff=1E-1       )





       def 						lowerCAmelCase     (   self							:			int       ):


             '''simple docstring'''



             self._test_attention_slicing_forward_pass(expected_max_diff=1E-2       )





       def 						lowerCAmelCase     (   self							:			Any       ):


             '''simple docstring'''



             self._test_save_load_local()





       def 						lowerCAmelCase     (   self							:			List[Any]       ):


             '''simple docstring'''



             self._test_inference_batch_single_identical(
                 expected_max_diff=1E-2					,      )




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

