
'''simple docstring'''

import sys
from collections import defaultdict




class    lowerCAmelCase       :


 def __init__(    self  : List[str]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[Any]     		=	[]


 def    _A	(    self  : Union[str, Any]			,							a__  : Optional[Any]    ):
  '''simple docstring'''

  return self.node_position[vertex]


 def    _A	(    self  : str			,							a__  : int			,							a__  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   str     		=	pos


 def    _A	(    self  : Union[str, Any]			,							a__  : List[Any]			,							a__  : Optional[int]			,							a__  : Any			,							a__  : List[Any]    ):
  '''simple docstring'''

  if start > size // 2 - 1:
   return
  else:
   if 2 * start + 2 >= size:
    lowerCAmelCase__     :   Optional[Any]     		=	2 * start + 1
   else:
    if heap[2 * start + 1] < heap[2 * start + 2]:
     lowerCAmelCase__     :   List[Any]     		=	2 * start + 1
    else:
     lowerCAmelCase__     :   int     		=	2 * start + 2
   if heap[smallest_child] < heap[start]:
    lowerCAmelCase__		,     lowerCAmelCase__     :   Union[str, Any]     		=	heap[smallest_child], positions[smallest_child]
    lowerCAmelCase__		,     lowerCAmelCase__     :   Optional[int]     		=	(
        heap[start],
        positions[start],
    )
    lowerCAmelCase__		,     lowerCAmelCase__     :   Any     		=	temp, tempa

    lowerCAmelCase__     :   List[str]     		=	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    _A	(    self  : List[Any]			,							a__  : List[Any]			,							a__  : List[Any]			,							a__  : Tuple			,							a__  : Tuple    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	position[index]

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

   if val < heap[parent]:
    lowerCAmelCase__     :   str     		=	heap[parent]
    lowerCAmelCase__     :   str     		=	position[parent]
    self.set_position(position[parent]			,							a__    )
   else:
    lowerCAmelCase__     :   str     		=	val
    lowerCAmelCase__     :   Tuple     		=	temp
    self.set_position(a__			,							a__    )
    break
   lowerCAmelCase__     :   List[str]     		=	parent
  else:
   lowerCAmelCase__     :   int     		=	val
   lowerCAmelCase__     :   Any     		=	temp
   self.set_position(a__			,							0    )


 def    _A	(    self  : str			,							a__  : Dict			,							a__  : Dict    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[Any]     		=	len(a__    ) // 2 - 1
  for i in range(a__			,							-1			,							-1    ):
   self.top_to_bottom(a__			,							a__			,							len(a__    )			,							a__    )


 def    _A	(    self  : List[Any]			,							a__  : int			,							a__  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Union[str, Any]     		=	positions[0]
  lowerCAmelCase__     :   Tuple     		=	sys.maxsize
  self.top_to_bottom(a__			,							0			,							len(a__    )			,							a__    )
  return temp



def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 lowerCAmelCase__     :   Optional[Any]     		=	Heap()

 lowerCAmelCase__     :   List[Any]     		=	[0] * len(lowerCamelCase_			)
 lowerCAmelCase__     :   int     		=	[-1] * len(lowerCamelCase_			)  # Neighboring Tree Vertex of selected vertex
 # Minimum Distance of explored vertex with neighboring vertex of partial tree
 # formed in graph
 lowerCAmelCase__     :   Dict     		=	[]  # Heap of Distance of vertices from their neighboring vertex
 lowerCAmelCase__     :   str     		=	[]

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

 lowerCAmelCase__     :   str     		=	[]
 lowerCAmelCase__     :   List[Any]     		=	1
 lowerCAmelCase__     :   Union[str, Any]     		=	sys.maxsize
 for neighbor, distance in adjacency_list[0]:
  lowerCAmelCase__     :   List[Any]     		=	0
  lowerCAmelCase__     :   Union[str, Any]     		=	distance
 heap.heapify(lowerCamelCase_      ,			lowerCamelCase_			)

 for _ in range(1      ,			len(lowerCamelCase_			)			):
  lowerCAmelCase__     :   int     		=	heap.delete_minimum(lowerCamelCase_      ,			lowerCamelCase_			)
  if visited[vertex] == 0:
   tree_edges.append((nbr_tv[vertex], vertex)			)
   lowerCAmelCase__     :   Dict     		=	1
   for neighbor, distance in adjacency_list[vertex]:
    if (
        visited[neighbor] == 0
        and distance < distance_tv[heap.get_position(lowerCamelCase_			)]
    ):
     lowerCAmelCase__     :   Optional[int]     		=	distance
     heap.bottom_to_top(
         lowerCamelCase_      ,			heap.get_position(lowerCamelCase_			)      ,			lowerCamelCase_      ,			lowerCamelCase_			)
     lowerCAmelCase__     :   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))







'''simple docstring'''

import tempfile

import numpy as np
import torch
from transformers import AutoTokenizer, TaEncoderModel

from diffusers import DDPMScheduler, UNetaDConditionModel
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.pipelines.deepfloyd_if import IFWatermarker
from diffusers.utils.testing_utils import torch_device

from ..test_pipelines_common import to_np




class    lowerCAmelCase       :


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  torch.manual_seed(0    )
  lowerCAmelCase__     :   List[str]     		=	TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"    )

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Optional[int]     		=	AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"    )

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Any     		=	UNetaDConditionModel(
      sample_size=32			,							layers_per_block=1			,							block_out_channels=[32, 64]			,							down_block_types=[
          "ResnetDownsampleBlock2D",
          "SimpleCrossAttnDownBlock2D",
      ]			,							mid_block_type="UNetMidBlock2DSimpleCrossAttn"			,							up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]			,							in_channels=3			,							out_channels=6			,							cross_attention_dim=32			,							encoder_hid_dim=32			,							attention_head_dim=8			,							addition_embed_type="text"			,							addition_embed_type_num_heads=2			,							cross_attention_norm="group_norm"			,							resnet_time_scale_shift="scale_shift"			,							act_fn="gelu"			,							)
  unet.set_attn_processor(AttnAddedKVProcessor()    )  # For reproducibility tests

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Union[str, Any]     		=	DDPMScheduler(
      num_train_timesteps=1000			,							beta_schedule="squaredcos_cap_v2"			,							beta_start=0.0001			,							beta_end=0.02			,							thresholding=a__			,							dynamic_thresholding_ratio=0.95			,							sample_max_value=1.0			,							prediction_type="epsilon"			,							variance_type="learned_range"			,							)

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Tuple     		=	IFWatermarker()

  return {
      "text_encoder": text_encoder,
      "tokenizer": tokenizer,
      "unet": unet,
      "scheduler": scheduler,
      "watermarker": watermarker,
      "safety_checker": None,
      "feature_extractor": None,
  }


 def    _A	(    self  : Dict    ):
  '''simple docstring'''

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Any     		=	TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"    )

  torch.manual_seed(0    )
  lowerCAmelCase__     :   List[Any]     		=	AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"    )

  torch.manual_seed(0    )
  lowerCAmelCase__     :   int     		=	UNetaDConditionModel(
      sample_size=32			,							layers_per_block=[1, 2]			,							block_out_channels=[32, 64]			,							down_block_types=[
          "ResnetDownsampleBlock2D",
          "SimpleCrossAttnDownBlock2D",
      ]			,							mid_block_type="UNetMidBlock2DSimpleCrossAttn"			,							up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]			,							in_channels=6			,							out_channels=6			,							cross_attention_dim=32			,							encoder_hid_dim=32			,							attention_head_dim=8			,							addition_embed_type="text"			,							addition_embed_type_num_heads=2			,							cross_attention_norm="group_norm"			,							resnet_time_scale_shift="scale_shift"			,							act_fn="gelu"			,							class_embed_type="timestep"			,							mid_block_scale_factor=1.414			,							time_embedding_act_fn="gelu"			,							time_embedding_dim=32			,							)
  unet.set_attn_processor(AttnAddedKVProcessor()    )  # For reproducibility tests

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Tuple     		=	DDPMScheduler(
      num_train_timesteps=1000			,							beta_schedule="squaredcos_cap_v2"			,							beta_start=0.0001			,							beta_end=0.02			,							thresholding=a__			,							dynamic_thresholding_ratio=0.95			,							sample_max_value=1.0			,							prediction_type="epsilon"			,							variance_type="learned_range"			,							)

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Tuple     		=	DDPMScheduler(
      num_train_timesteps=1000			,							beta_schedule="squaredcos_cap_v2"			,							beta_start=0.0001			,							beta_end=0.02			,							)

  torch.manual_seed(0    )
  lowerCAmelCase__     :   Dict     		=	IFWatermarker()

  return {
      "text_encoder": text_encoder,
      "tokenizer": tokenizer,
      "unet": unet,
      "scheduler": scheduler,
      "image_noising_scheduler": image_noising_scheduler,
      "watermarker": watermarker,
      "safety_checker": None,
      "feature_extractor": None,
  }


 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Union[str, Any]     		=	self.get_dummy_components()
  lowerCAmelCase__     :   Dict     		=	self.pipeline_class(**a__    )
  pipe.to(a__    )
  pipe.set_progress_bar_config(disable=a__    )

  lowerCAmelCase__     :   Tuple     		=	self.get_dummy_inputs(a__    )

  lowerCAmelCase__     :   str     		=	inputs["prompt"]
  lowerCAmelCase__     :   Optional[Any]     		=	inputs["generator"]
  lowerCAmelCase__     :   str     		=	inputs["num_inference_steps"]
  lowerCAmelCase__     :   int     		=	inputs["output_type"]

  if "image" in inputs:
   lowerCAmelCase__     :   Optional[int]     		=	inputs["image"]
  else:
   lowerCAmelCase__     :   str     		=	None

  if "mask_image" in inputs:
   lowerCAmelCase__     :   List[str]     		=	inputs["mask_image"]
  else:
   lowerCAmelCase__     :   str     		=	None

  if "original_image" in inputs:
   lowerCAmelCase__     :   Optional[int]     		=	inputs["original_image"]
  else:
   lowerCAmelCase__     :   Union[str, Any]     		=	None

  lowerCAmelCase__		,     lowerCAmelCase__     :   Dict     		=	pipe.encode_prompt(a__    )

  # inputs with prompt converted to embeddings
  lowerCAmelCase__     :   Dict     		=	{
      "prompt_embeds": prompt_embeds,
      "negative_prompt_embeds": negative_prompt_embeds,
      "generator": generator,
      "num_inference_steps": num_inference_steps,
      "output_type": output_type,
  }

  if image is not None:
   lowerCAmelCase__     :   Optional[Any]     		=	image

  if mask_image is not None:
   lowerCAmelCase__     :   Optional[int]     		=	mask_image

  if original_image is not None:
   lowerCAmelCase__     :   Optional[Any]     		=	original_image

  # set all optional components to None
  for optional_component in pipe._optional_components:
   setattr(a__			,							a__			,							a__    )

  lowerCAmelCase__     :   Optional[int]     		=	pipe(**a__    )[0]

  with tempfile.TemporaryDirectory() as tmpdir:
   pipe.save_pretrained(a__    )
   lowerCAmelCase__     :   Tuple     		=	self.pipeline_class.from_pretrained(a__    )
   pipe_loaded.to(a__    )
   pipe_loaded.set_progress_bar_config(disable=a__    )

  pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()    )  # For reproducibility tests

  for optional_component in pipe._optional_components:
   self.assertTrue(
       getattr(a__			,							a__    ) is None			,							F'''`{optional_component}` did not stay set to None after loading.'''			,							)

  lowerCAmelCase__     :   Union[str, Any]     		=	self.get_dummy_inputs(a__    )

  lowerCAmelCase__     :   Any     		=	inputs["generator"]
  lowerCAmelCase__     :   Union[str, Any]     		=	inputs["num_inference_steps"]
  lowerCAmelCase__     :   str     		=	inputs["output_type"]

  # inputs with prompt converted to embeddings
  lowerCAmelCase__     :   int     		=	{
      "prompt_embeds": prompt_embeds,
      "negative_prompt_embeds": negative_prompt_embeds,
      "generator": generator,
      "num_inference_steps": num_inference_steps,
      "output_type": output_type,
  }

  if image is not None:
   lowerCAmelCase__     :   Tuple     		=	image

  if mask_image is not None:
   lowerCAmelCase__     :   int     		=	mask_image

  if original_image is not None:
   lowerCAmelCase__     :   List[Any]     		=	original_image

  lowerCAmelCase__     :   Dict     		=	pipe_loaded(**a__    )[0]

  lowerCAmelCase__     :   int     		=	np.abs(to_np(a__    ) - to_np(a__    )    ).max()
  self.assertLess(a__			,							1e-4    )


 def    _A	(    self  : Any    ):
  '''simple docstring'''

  lowerCAmelCase__     :   str     		=	self.get_dummy_components()
  lowerCAmelCase__     :   int     		=	self.pipeline_class(**a__    )
  pipe.to(a__    )
  pipe.set_progress_bar_config(disable=a__    )

  lowerCAmelCase__     :   Any     		=	self.get_dummy_inputs(a__    )
  lowerCAmelCase__     :   Union[str, Any]     		=	pipe(**a__    )[0]

  with tempfile.TemporaryDirectory() as tmpdir:
   pipe.save_pretrained(a__    )
   lowerCAmelCase__     :   str     		=	self.pipeline_class.from_pretrained(a__    )
   pipe_loaded.to(a__    )
   pipe_loaded.set_progress_bar_config(disable=a__    )

  pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()    )  # For reproducibility tests

  lowerCAmelCase__     :   str     		=	self.get_dummy_inputs(a__    )
  lowerCAmelCase__     :   Union[str, Any]     		=	pipe_loaded(**a__    )[0]

  lowerCAmelCase__     :   Union[str, Any]     		=	np.abs(to_np(a__    ) - to_np(a__    )    ).max()
  self.assertLess(a__			,							1e-4    )





