

import sys
from collections import defaultdict



class SCREAMING_SNAKE_CASE     :
  """simple docstring"""






  def __init__(      self			:   int   )							->     str:






     """simple docstring"""







     __lowerCAmelCase  :      Dict    =						[]







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]	,							lowerCAmelCase			:   List[str]   )							->     List[str]:






     """simple docstring"""







     return self.node_position[vertex]







  def 	SCREAMING_SNAKE_CASE   (      self			:   List[str]	,							lowerCAmelCase			:   List[Any]	,							lowerCAmelCase			:   Any   )							->     List[str]:






     """simple docstring"""







     __lowerCAmelCase  :      str    =						pos







  def 	SCREAMING_SNAKE_CASE   (      self			:   Dict	,							lowerCAmelCase			:   str	,							lowerCAmelCase			:   List[Any]	,							lowerCAmelCase			:   Tuple	,							lowerCAmelCase			:   Optional[Any]   )							->     List[str]:






     """simple docstring"""







     if start > size // 2 - 1:
        return
     else:
        if 2 * start + 2 >= size:
           __lowerCAmelCase  :      Optional[int]    =						2 * start + 1
        else:
           if heap[2 * start + 1] < heap[2 * start + 2]:
              __lowerCAmelCase  :      str    =						2 * start + 1
           else:
              __lowerCAmelCase  :      List[str]    =						2 * start + 2
        if heap[smallest_child] < heap[start]:
           __lowerCAmelCase   ,__lowerCAmelCase  :      List[str]    =						heap[smallest_child], positions[smallest_child]
           __lowerCAmelCase   ,__lowerCAmelCase  :      Optional[int]    =						(
               heap[start],
               positions[start],
           )
           __lowerCAmelCase   ,__lowerCAmelCase  :      Tuple    =						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]	,							lowerCAmelCase   )

           self.top_to_bottom(lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Dict	,							lowerCAmelCase			:   Any	,							lowerCAmelCase			:   Any	,							lowerCAmelCase			:   List[Any]	,							lowerCAmelCase			:   List[Any]   )							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      List[Any]    =						position[index]

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

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







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any	,							lowerCAmelCase			:   Any	,							lowerCAmelCase			:   Tuple   )							->     str:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[int]    =						len(lowerCAmelCase   ) // 2 - 1
     for i in range(lowerCAmelCase	,							-1	,							-1   ):
        self.top_to_bottom(lowerCAmelCase	,							lowerCAmelCase	,							len(lowerCAmelCase   )	,							lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]	,							lowerCAmelCase			:   Union[str, Any]	,							lowerCAmelCase			:   Tuple   )							->     Union[str, Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[int]    =						positions[0]
     __lowerCAmelCase  :      int    =						sys.maxsize
     self.top_to_bottom(lowerCAmelCase	,							0	,							len(lowerCAmelCase   )	,							lowerCAmelCase   )
     return temp






def      snake_case_				(__A					:						List[Any]					)      ->     Dict:
   __lowerCAmelCase  :      Optional[Any]    =						Heap()

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

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

   __lowerCAmelCase  :      str    =						[]
   __lowerCAmelCase  :      Any    =						1
   __lowerCAmelCase  :      str    =						sys.maxsize
   for neighbor, distance in adjacency_list[0]:
      __lowerCAmelCase  :      str    =						0
      __lowerCAmelCase  :      Optional[Any]    =						distance
   heap.heapify(__A ,       __A					)

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





import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest



class SCREAMING_SNAKE_CASE     (  a_			):
  """simple docstring"""






  lowerCamelCase   :      Dict										=(EulerDiscreteScheduler,)
  lowerCamelCase   :      Dict										=10







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]	,							**lowerCAmelCase			:   Union[str, Any]   )							->     List[str]:






     """simple docstring"""







     __lowerCAmelCase  :      Dict    =						{
         """num_train_timesteps""": 11_00,
         """beta_start""": 0.0001,
         """beta_end""": 0.02,
         """beta_schedule""": """linear""",
     }

     config.update(**lowerCAmelCase   )
     return config







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     List[str]:






     """simple docstring"""







     for timesteps in [10, 50, 1_00, 10_00]:
        self.check_over_configs(num_train_timesteps=lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Tuple   )							->     Tuple:






     """simple docstring"""







     for beta_start, beta_end in zip([0.0_0001, 0.0001, 0.001]	,							[0.0002, 0.002, 0.02]   ):
        self.check_over_configs(beta_start=lowerCAmelCase	,							beta_end=lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Union[str, Any]   )							->     str:






     """simple docstring"""







     for schedule in ["linear", "scaled_linear"]:
        self.check_over_configs(beta_schedule=lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     List[Any]:






     """simple docstring"""







     for prediction_type in ["epsilon", "v_prediction"]:
        self.check_over_configs(prediction_type=lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Union[str, Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Any    =						self.scheduler_classes[0]
     __lowerCAmelCase  :      int    =						self.get_scheduler_config()
     __lowerCAmelCase  :      Any    =						scheduler_class(**lowerCAmelCase   )

     scheduler.set_timesteps(self.num_inference_steps   )

     __lowerCAmelCase  :      str    =						torch.manual_seed(0   )

     __lowerCAmelCase  :      List[Any]    =						self.dummy_model()
     __lowerCAmelCase  :      Dict    =						self.dummy_sample_deter * scheduler.init_noise_sigma
     __lowerCAmelCase  :      int    =						sample.to(lowerCAmelCase   )

     for i, t in enumerate(scheduler.timesteps   ):
        __lowerCAmelCase  :      Tuple    =						scheduler.scale_model_input(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      Dict    =						model(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      str    =						scheduler.step(lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							generator=lowerCAmelCase   )
        __lowerCAmelCase  :      Optional[int]    =						output.prev_sample

     __lowerCAmelCase  :      str    =						torch.sum(torch.abs(lowerCAmelCase   )   )
     __lowerCAmelCase  :      Optional[int]    =						torch.mean(torch.abs(lowerCAmelCase   )   )

     assert abs(result_sum.item() - 10.0807   ) < 1e-2
     assert abs(result_mean.item() - 0.0131   ) < 1e-3







  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     Union[str, Any]:






     """simple docstring"""







     __lowerCAmelCase  :      List[Any]    =						self.scheduler_classes[0]
     __lowerCAmelCase  :      List[Any]    =						self.get_scheduler_config(prediction_type="""v_prediction"""   )
     __lowerCAmelCase  :      List[str]    =						scheduler_class(**lowerCAmelCase   )

     scheduler.set_timesteps(self.num_inference_steps   )

     __lowerCAmelCase  :      Any    =						torch.manual_seed(0   )

     __lowerCAmelCase  :      int    =						self.dummy_model()
     __lowerCAmelCase  :      List[str]    =						self.dummy_sample_deter * scheduler.init_noise_sigma
     __lowerCAmelCase  :      List[Any]    =						sample.to(lowerCAmelCase   )

     for i, t in enumerate(scheduler.timesteps   ):
        __lowerCAmelCase  :      Any    =						scheduler.scale_model_input(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      Any    =						model(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      Dict    =						scheduler.step(lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							generator=lowerCAmelCase   )
        __lowerCAmelCase  :      Dict    =						output.prev_sample

     __lowerCAmelCase  :      List[str]    =						torch.sum(torch.abs(lowerCAmelCase   )   )
     __lowerCAmelCase  :      Optional[int]    =						torch.mean(torch.abs(lowerCAmelCase   )   )

     assert abs(result_sum.item() - 0.0002   ) < 1e-2
     assert abs(result_mean.item() - 2.2676e-06   ) < 1e-3







  def 	SCREAMING_SNAKE_CASE   (      self			:   Tuple   )							->     Dict:






     """simple docstring"""







     __lowerCAmelCase  :      List[Any]    =						self.scheduler_classes[0]
     __lowerCAmelCase  :      Dict    =						self.get_scheduler_config()
     __lowerCAmelCase  :      Optional[int]    =						scheduler_class(**lowerCAmelCase   )

     scheduler.set_timesteps(self.num_inference_steps	,							device=lowerCAmelCase   )

     __lowerCAmelCase  :      Union[str, Any]    =						torch.manual_seed(0   )

     __lowerCAmelCase  :      Dict    =						self.dummy_model()
     __lowerCAmelCase  :      Dict    =						self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
     __lowerCAmelCase  :      Dict    =						sample.to(lowerCAmelCase   )

     for t in scheduler.timesteps:
        __lowerCAmelCase  :      Union[str, Any]    =						scheduler.scale_model_input(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      List[str]    =						model(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      int    =						scheduler.step(lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							generator=lowerCAmelCase   )
        __lowerCAmelCase  :      Any    =						output.prev_sample

     __lowerCAmelCase  :      int    =						torch.sum(torch.abs(lowerCAmelCase   )   )
     __lowerCAmelCase  :      str    =						torch.mean(torch.abs(lowerCAmelCase   )   )

     assert abs(result_sum.item() - 10.0807   ) < 1e-2
     assert abs(result_mean.item() - 0.0131   ) < 1e-3







  def 	SCREAMING_SNAKE_CASE   (      self			:   Dict   )							->     str:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[int]    =						self.scheduler_classes[0]
     __lowerCAmelCase  :      Optional[int]    =						self.get_scheduler_config()
     __lowerCAmelCase  :      List[Any]    =						scheduler_class(**lowerCAmelCase	,							use_karras_sigmas=lowerCAmelCase   )

     scheduler.set_timesteps(self.num_inference_steps	,							device=lowerCAmelCase   )

     __lowerCAmelCase  :      str    =						torch.manual_seed(0   )

     __lowerCAmelCase  :      str    =						self.dummy_model()
     __lowerCAmelCase  :      str    =						self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
     __lowerCAmelCase  :      int    =						sample.to(lowerCAmelCase   )

     for t in scheduler.timesteps:
        __lowerCAmelCase  :      int    =						scheduler.scale_model_input(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      Dict    =						model(lowerCAmelCase	,							lowerCAmelCase   )

        __lowerCAmelCase  :      Tuple    =						scheduler.step(lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							generator=lowerCAmelCase   )
        __lowerCAmelCase  :      List[Any]    =						output.prev_sample

     __lowerCAmelCase  :      Tuple    =						torch.sum(torch.abs(lowerCAmelCase   )   )
     __lowerCAmelCase  :      Any    =						torch.mean(torch.abs(lowerCAmelCase   )   )

     assert abs(result_sum.item() - 124.52_2994_9951_1719   ) < 1e-2
     assert abs(result_mean.item() - 0.1_6213_9326_3339_9963   ) < 1e-3


