





'''simple docstring'''

from typing import Any, Dict, List, Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_vision_available():
    from PIL import Image

    from ..image_utils import load_image

if is_torch_available():
    import torch

    from transformers.modeling_outputs import BaseModelOutput

    from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

a        =						logging.get_logger(__name__)







@add_end_docstrings(_snake_case			)
class __a (   _snake_case			):





   def __init__(					self				:			Any				,**lowerCamelCase				:			Any    ):

      '''simple docstring'''

      super().__init__(**lowerCamelCase    )

      if self.framework == "tf":
         raise ValueError(f"""The {self.__class__} is only available in PyTorch."""    )

      requires_backends(self				,"""vision"""    )
      self.check_model_type(lowerCamelCase    )





   def __call__(					self				:			List[str]				,lowerCamelCase				:			Union[str, "Image.Image", List[Dict[str, Any]]]				,lowerCamelCase				:			Union[str, List[str]] = None				,**lowerCamelCase				:			Optional[Any]				,):

      '''simple docstring'''

      if "text_queries" in kwargs:
         __SCREAMING_SNAKE_CASE      							=       kwargs.pop("""text_queries"""    )

      if isinstance(lowerCamelCase				,(str, Image.Image)    ):
         __SCREAMING_SNAKE_CASE      							=       {"""image""": image, """candidate_labels""": candidate_labels}
      else:
         __SCREAMING_SNAKE_CASE      							=       image
      __SCREAMING_SNAKE_CASE      							=       super().__call__(lowerCamelCase				,**lowerCamelCase    )
      return results





   def      UpperCAmelCase__     (					self				:			Any				,**lowerCamelCase				:			Any    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       {}
      if "threshold" in kwargs:
         __SCREAMING_SNAKE_CASE      							=       kwargs["""threshold"""]
      if "top_k" in kwargs:
         __SCREAMING_SNAKE_CASE      							=       kwargs["""top_k"""]
      return {}, {}, postprocess_params





   def      UpperCAmelCase__     (					self				:			Tuple				,lowerCamelCase				:			List[Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       load_image(inputs["""image"""]    )
      __SCREAMING_SNAKE_CASE      							=       inputs["""candidate_labels"""]
      if isinstance(lowerCamelCase				,lowerCamelCase    ):
         __SCREAMING_SNAKE_CASE      							=       candidate_labels.split(""","""    )

      __SCREAMING_SNAKE_CASE      							=       torch.tensor([[image.height, image.width]]				,dtype=torch.intaa    )
      for i, candidate_label in enumerate(lowerCamelCase    ):
         __SCREAMING_SNAKE_CASE      							=       self.tokenizer(lowerCamelCase				,return_tensors=self.framework    )
         __SCREAMING_SNAKE_CASE      							=       self.image_processor(lowerCamelCase				,return_tensors=self.framework    )
         yield {
             "is_last": i == len(lowerCamelCase    ) - 1,
             "target_size": target_size,
             "candidate_label": candidate_label,
             **text_inputs,
             **image_features,
         }





   def      UpperCAmelCase__     (					self				:			Optional[Any]				,lowerCamelCase				:			Union[str, Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       model_inputs.pop("""target_size"""    )
      __SCREAMING_SNAKE_CASE      							=       model_inputs.pop("""candidate_label"""    )
      __SCREAMING_SNAKE_CASE      							=       model_inputs.pop("""is_last"""    )

      __SCREAMING_SNAKE_CASE      							=       self.model(**lowerCamelCase    )

      __SCREAMING_SNAKE_CASE      							=       {"""target_size""": target_size, """candidate_label""": candidate_label, """is_last""": is_last, **outputs}
      return model_outputs





   def      UpperCAmelCase__     (					self				:			Any				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			Any=0.1				,lowerCamelCase				:			Optional[int]=None    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       []
      for model_output in model_outputs:
         __SCREAMING_SNAKE_CASE      							=       model_output["""candidate_label"""]
         __SCREAMING_SNAKE_CASE      							=       BaseModelOutput(lowerCamelCase    )
         __SCREAMING_SNAKE_CASE      							=       self.image_processor.post_process_object_detection(
             outputs=lowerCamelCase				,threshold=lowerCamelCase				,target_sizes=model_output["""target_size"""]    )[0]

         for index in outputs["scores"].nonzero():
            __SCREAMING_SNAKE_CASE      							=       outputs["""scores"""][index].item()
            __SCREAMING_SNAKE_CASE      							=       self._get_bounding_box(outputs["""boxes"""][index][0]    )

            __SCREAMING_SNAKE_CASE      							=       {"""score""": score, """label""": label, """box""": box}
            results.append(lowerCamelCase    )

      __SCREAMING_SNAKE_CASE      							=       sorted(lowerCamelCase				,key=lambda lowerCamelCase    : x["score"]				,reverse=lowerCamelCase    )
      if top_k:
         __SCREAMING_SNAKE_CASE      							=       results[:top_k]

      return results





   def      UpperCAmelCase__     (					self				:			Dict				,lowerCamelCase				:			"torch.Tensor"    ):

      '''simple docstring'''

      if self.framework != "pt":
         raise ValueError("""The ZeroShotObjectDetectionPipeline is only available in PyTorch."""    )
      __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       box.int().tolist()
      __SCREAMING_SNAKE_CASE      							=       {
          """xmin""": xmin,
          """ymin""": ymin,
          """xmax""": xmax,
          """ymax""": ymax,
      }
      return bbox












'''simple docstring'''

import sys
from collections import defaultdict







class __a :





   def __init__(					self				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       []





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			List[Any]    ):

      '''simple docstring'''

      return self.node_position[vertex]





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			str				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       pos





   def      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Union[str, Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Any    ):

      '''simple docstring'''

      if start > size // 2 - 1:
         return
      else:
         if 2 * start + 2 >= size:
            __SCREAMING_SNAKE_CASE      							=       2 * start + 1
         else:
            if heap[2 * start + 1] < heap[2 * start + 2]:
               __SCREAMING_SNAKE_CASE      							=       2 * start + 1
            else:
               __SCREAMING_SNAKE_CASE      							=       2 * start + 2
         if heap[smallest_child] < heap[start]:
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       heap[smallest_child], positions[smallest_child]
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       (
                heap[start],
                positions[start],
            )
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       temp, tempa

            __SCREAMING_SNAKE_CASE      							=       self.get_position(positions[smallest_child]    )
            self.set_position(
                positions[smallest_child]				,self.get_position(positions[start]    )    )
            self.set_position(positions[start]				,lowerCamelCase    )

            self.top_to_bottom(lowerCamelCase				,lowerCamelCase				,lowerCamelCase				,lowerCamelCase    )





   def      UpperCAmelCase__     (					self				:			Any				,lowerCamelCase				:			int				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Optional[Any]				,lowerCamelCase				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       position[index]

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

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





   def      UpperCAmelCase__     (					self				:			Tuple				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       len(lowerCamelCase    ) // 2 - 1
      for i in range(lowerCamelCase				,-1				,-1    ):
         self.top_to_bottom(lowerCamelCase				,lowerCamelCase				,len(lowerCamelCase    )				,lowerCamelCase    )





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       positions[0]
      __SCREAMING_SNAKE_CASE      							=       sys.maxsize
      self.top_to_bottom(lowerCamelCase				,0				,len(lowerCamelCase    )				,lowerCamelCase    )
      return temp





def 						__magic_name__       (							__UpperCAmelCase      )						->					Optional[Any]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       Heap()

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

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

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

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


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





