





from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer



@dataclass
class 							_UpperCAmelCase       (       _UpperCamelCase       ):

  """simple docstring"""


  a_              =					42





class 							_UpperCAmelCase       (       _UpperCamelCase						,       _UpperCamelCase       ):

  """simple docstring"""


  @register_to_config
  def __init__(							self					:						Union[str, Any]   ,    lowerCAmelCase_					:						int = 3   ,    lowerCAmelCase_					:						int = 3   ,    lowerCAmelCase_					:						Tuple[str] = ("DownEncoderBlock2D",)   ,    lowerCAmelCase_					:						Tuple[str] = ("UpDecoderBlock2D",)   ,    lowerCAmelCase_					:						Tuple[int] = (6_4,)   ,    lowerCAmelCase_					:						int = 1   ,    lowerCAmelCase_					:						str = "silu"   ,    lowerCAmelCase_					:						int = 3   ,    lowerCAmelCase_					:						int = 3_2   ,    lowerCAmelCase_					:						int = 2_5_6   ,    lowerCAmelCase_					:						int = 3_2   ,    lowerCAmelCase_					:						Optional[int] = None   ,    lowerCAmelCase_					:						float = 0.1_82_15   ,    lowerCAmelCase_					:						str = "group"   ,    )				->		List[Any]:
     super().__init__()

     # pass init params to Encoder
     __lowerCAmelCase				      =      Encoder(
         in_channels=lowerCAmelCase_   ,    out_channels=lowerCAmelCase_   ,    down_block_types=lowerCAmelCase_   ,    block_out_channels=lowerCAmelCase_   ,    layers_per_block=lowerCAmelCase_   ,    act_fn=lowerCAmelCase_   ,    norm_num_groups=lowerCAmelCase_   ,    double_z=lowerCAmelCase_   ,    )

     __lowerCAmelCase				      =      vq_embed_dim if vq_embed_dim is not None else latent_channels

     __lowerCAmelCase				      =      nn.Convad(lowerCAmelCase_   ,    lowerCAmelCase_   ,    1	)
     __lowerCAmelCase				      =      VectorQuantizer(lowerCAmelCase_   ,    lowerCAmelCase_   ,    beta=0.25   ,    remap=lowerCAmelCase_   ,    sane_index_shape=lowerCAmelCase_	)
     __lowerCAmelCase				      =      nn.Convad(lowerCAmelCase_   ,    lowerCAmelCase_   ,    1	)

     # pass init params to Decoder
     __lowerCAmelCase				      =      Decoder(
         in_channels=lowerCAmelCase_   ,    out_channels=lowerCAmelCase_   ,    up_block_types=lowerCAmelCase_   ,    block_out_channels=lowerCAmelCase_   ,    layers_per_block=lowerCAmelCase_   ,    act_fn=lowerCAmelCase_   ,    norm_num_groups=lowerCAmelCase_   ,    norm_type=lowerCAmelCase_   ,    )






  @apply_forward_hook
  def 							lowercase						(							self					:						Optional[int]   ,    lowerCAmelCase_					:						torch.FloatTensor   ,    lowerCAmelCase_					:						bool = True	)				->		VQEncoderOutput:
     __lowerCAmelCase				      =      self.encoder(lowerCAmelCase_	)
     __lowerCAmelCase				      =      self.quant_conv(lowerCAmelCase_	)

     if not return_dict:
        return (h,)

     return VQEncoderOutput(latents=lowerCAmelCase_	)






  @apply_forward_hook
  def 							lowercase						(							self					:						Optional[Any]   ,    lowerCAmelCase_					:						torch.FloatTensor   ,    lowerCAmelCase_					:						bool = False   ,    lowerCAmelCase_					:						bool = True	)				->		Union[DecoderOutput, torch.FloatTensor]:
     # also go through quantization layer
     if not force_not_quantize:
        __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase				      =      self.quantize(lowerCAmelCase_	)
     else:
        __lowerCAmelCase				      =      h
     __lowerCAmelCase				      =      self.post_quant_conv(lowerCAmelCase_	)
     __lowerCAmelCase				      =      self.decoder(lowerCAmelCase_   ,    quant if self.config.norm_type == 'spatial' else None	)

     if not return_dict:
        return (dec,)

     return DecoderOutput(sample=lowerCAmelCase_	)






  def 							lowercase						(							self					:						Dict   ,    lowerCAmelCase_					:						torch.FloatTensor   ,    lowerCAmelCase_					:						bool = True	)				->		Union[DecoderOutput, torch.FloatTensor]:
     __lowerCAmelCase				      =      sample
     __lowerCAmelCase				      =      self.encode(lowerCAmelCase_	).latents
     __lowerCAmelCase				      =      self.decode(lowerCAmelCase_	).sample

     if not return_dict:
        return (dec,)

     return DecoderOutput(sample=lowerCAmelCase_	)





'''simple docstring'''



import sys
from collections import defaultdict





class   UpperCAmelCase_    :





    """simple docstring"""






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







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_      )							->	Any:
         return self.node_position[vertex]







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )							->	Tuple:
         __lowerCamelCase  :      Optional[int]														=						pos







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )							->	int:
         if start > size // 2 - 1:
              return
         else:
              if 2 * start + 2 >= size:
                   __lowerCamelCase  :      str														=						2 * start + 1
              else:
                   if heap[2 * start + 1] < heap[2 * start + 2]:
                        __lowerCamelCase  :      Optional[Any]														=						2 * start + 1
                   else:
                        __lowerCamelCase  :      int														=						2 * start + 2
              if heap[smallest_child] < heap[start]:
                   __lowerCamelCase							,			__lowerCamelCase  :      Optional[Any]														=						heap[smallest_child], positions[smallest_child]
                   __lowerCamelCase							,			__lowerCamelCase  :      int														=						(
                       heap[start],
                       positions[start],
                   )
                   __lowerCamelCase							,			__lowerCamelCase  :      str														=						temp, tempa

                   __lowerCamelCase  :      Dict														=						self.get_position(positions[smallest_child]      )
                   self.set_position(
                       positions[smallest_child]     ,	self.get_position(positions[start]      )      )
                   self.set_position(positions[start]     ,	SCREAMING_SNAKE_CASE_      )

                   self.top_to_bottom(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )							->	Any:
         __lowerCamelCase  :      Any														=						position[index]

         while index != 0:
              __lowerCamelCase  :      Union[str, Any]														=						int((index - 2) / 2      ) if index % 2 == 0 else int((index - 1) / 2      )

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







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )							->	Optional[int]:
         __lowerCamelCase  :      Optional[int]														=						len(SCREAMING_SNAKE_CASE_      ) // 2 - 1
         for i in range(SCREAMING_SNAKE_CASE_     ,	-1     ,	-1      ):
              self.top_to_bottom(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	len(SCREAMING_SNAKE_CASE_      )     ,	SCREAMING_SNAKE_CASE_      )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )							->	List[Any]:
         __lowerCamelCase  :      Any														=						positions[0]
         __lowerCamelCase  :      Union[str, Any]														=						sys.maxsize
         self.top_to_bottom(SCREAMING_SNAKE_CASE_     ,	0     ,	len(SCREAMING_SNAKE_CASE_      )     ,	SCREAMING_SNAKE_CASE_      )
         return temp







def      UpperCAmelCase__   (      UpperCAmelCase_       :							Optional[int]				)	->						str:
     __lowerCamelCase  :      List[Any]														=						Heap()

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

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

     __lowerCamelCase  :      Tuple														=						[]
     __lowerCamelCase  :      Dict														=						1
     __lowerCamelCase  :      str														=						sys.maxsize
     for neighbor, distance in adjacency_list[0]:
          __lowerCamelCase  :      Any														=						0
          __lowerCamelCase  :      Any														=						distance
     heap.heapify(UpperCAmelCase_ ,       UpperCAmelCase_				)

     for _ in range(1 ,       len(UpperCAmelCase_				)				):
          __lowerCamelCase  :      List[Any]														=						heap.delete_minimum(UpperCAmelCase_ ,       UpperCAmelCase_				)
          if visited[vertex] == 0:
               tree_edges.append((nbr_tv[vertex], vertex)				)
               __lowerCamelCase  :      Union[str, Any]														=						1
               for neighbor, distance in adjacency_list[vertex]:
                    if (
                        visited[neighbor] == 0
                        and distance < distance_tv[heap.get_position(UpperCAmelCase_				)]
                    ):
                         __lowerCamelCase  :      Dict														=						distance
                         heap.bottom_to_top(
                             UpperCAmelCase_ ,       heap.get_position(UpperCAmelCase_				) ,       UpperCAmelCase_ ,       UpperCAmelCase_				)
                         __lowerCamelCase  :      str														=						vertex
     return tree_edges


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






