
'''simple docstring'''

import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class 		_a     (							SCREAMING_SNAKE_CASE  ):







   """simple docstring"""




   A		= (HeunDiscreteScheduler,)
   A		= 10






   def 					__a			(       self    ,**__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  str								=		{
        'num_train_timesteps': 1100,
        'beta_start': 0.0001,
        'beta_end': 0.02,
        'beta_schedule': 'linear',
    }

    config.update(**__SCREAMING_SNAKE_CASE      )
    return config






   def 					__a			(       self      ):
    for timesteps in [10, 50, 100, 1000]:
     self.check_over_configs(num_train_timesteps=__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    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=__SCREAMING_SNAKE_CASE    ,beta_end=__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    for schedule in ["linear", "scaled_linear", "exp"]:
     self.check_over_configs(beta_schedule=__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    for clip_sample_range in [1.0, 2.0, 3.0]:
     self.check_over_configs(clip_sample_range=__SCREAMING_SNAKE_CASE    ,clip_sample=__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    for prediction_type in ["epsilon", "v_prediction", "sample"]:
     self.check_over_configs(prediction_type=__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		self.scheduler_classes[0]
    SCREAMING_SNAKE_CASE  :  List[Any]								=		self.get_scheduler_config()
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		scheduler_class(**__SCREAMING_SNAKE_CASE      )

    scheduler.set_timesteps(self.num_inference_steps      )

    SCREAMING_SNAKE_CASE  :  List[Any]								=		self.dummy_model()
    SCREAMING_SNAKE_CASE  :  Any								=		self.dummy_sample_deter * scheduler.init_noise_sigma
    SCREAMING_SNAKE_CASE  :  str								=		sample.to(__SCREAMING_SNAKE_CASE      )

    for i, t in enumerate(scheduler.timesteps      ):
     SCREAMING_SNAKE_CASE  :  Any								=		scheduler.scale_model_input(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  str								=		model(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Any								=		scheduler.step(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
     SCREAMING_SNAKE_CASE  :  Tuple								=		output.prev_sample

    SCREAMING_SNAKE_CASE  :  List[Any]								=		torch.sum(torch.abs(__SCREAMING_SNAKE_CASE      )      )
    SCREAMING_SNAKE_CASE  :  List[str]								=		torch.mean(torch.abs(__SCREAMING_SNAKE_CASE      )      )

    if torch_device in ["cpu", "mps"]:
     assert abs(result_sum.item() - 0.1233      ) < 1e-2
     assert abs(result_mean.item() - 0.0002      ) < 1e-3
    else:
     # CUDA
     assert abs(result_sum.item() - 0.1233      ) < 1e-2
     assert abs(result_mean.item() - 0.0002      ) < 1e-3






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		self.scheduler_classes[0]
    SCREAMING_SNAKE_CASE  :  List[Any]								=		self.get_scheduler_config(prediction_type='v_prediction'      )
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		scheduler_class(**__SCREAMING_SNAKE_CASE      )

    scheduler.set_timesteps(self.num_inference_steps      )

    SCREAMING_SNAKE_CASE  :  List[str]								=		self.dummy_model()
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		self.dummy_sample_deter * scheduler.init_noise_sigma
    SCREAMING_SNAKE_CASE  :  int								=		sample.to(__SCREAMING_SNAKE_CASE      )

    for i, t in enumerate(scheduler.timesteps      ):
     SCREAMING_SNAKE_CASE  :  str								=		scheduler.scale_model_input(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Optional[Any]								=		model(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Tuple								=		scheduler.step(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
     SCREAMING_SNAKE_CASE  :  List[str]								=		output.prev_sample

    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		torch.sum(torch.abs(__SCREAMING_SNAKE_CASE      )      )
    SCREAMING_SNAKE_CASE  :  List[Any]								=		torch.mean(torch.abs(__SCREAMING_SNAKE_CASE      )      )

    if torch_device in ["cpu", "mps"]:
     assert abs(result_sum.item() - 4.6934e-07      ) < 1e-2
     assert abs(result_mean.item() - 6.1112e-10      ) < 1e-3
    else:
     # CUDA
     assert abs(result_sum.item() - 4.693_4286_5017_0972e-07      ) < 1e-2
     assert abs(result_mean.item() - 0.0002      ) < 1e-3






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		self.scheduler_classes[0]
    SCREAMING_SNAKE_CASE  :  List[str]								=		self.get_scheduler_config()
    SCREAMING_SNAKE_CASE  :  List[Any]								=		scheduler_class(**__SCREAMING_SNAKE_CASE      )

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

    SCREAMING_SNAKE_CASE  :  List[str]								=		self.dummy_model()
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		self.dummy_sample_deter.to(__SCREAMING_SNAKE_CASE      ) * scheduler.init_noise_sigma

    for t in scheduler.timesteps:
     SCREAMING_SNAKE_CASE  :  str								=		scheduler.scale_model_input(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Dict								=		model(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Optional[Any]								=		scheduler.step(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
     SCREAMING_SNAKE_CASE  :  List[Any]								=		output.prev_sample

    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		torch.sum(torch.abs(__SCREAMING_SNAKE_CASE      )      )
    SCREAMING_SNAKE_CASE  :  List[Any]								=		torch.mean(torch.abs(__SCREAMING_SNAKE_CASE      )      )

    if str(__SCREAMING_SNAKE_CASE      ).startswith('cpu'      ):
     # The following sum varies between 148 and 156 on mps. Why?
     assert abs(result_sum.item() - 0.1233      ) < 1e-2
     assert abs(result_mean.item() - 0.0002      ) < 1e-3
    elif str(__SCREAMING_SNAKE_CASE      ).startswith('mps'      ):
     # Larger tolerance on mps
     assert abs(result_mean.item() - 0.0002      ) < 1e-2
    else:
     # CUDA
     assert abs(result_sum.item() - 0.1233      ) < 1e-2
     assert abs(result_mean.item() - 0.0002      ) < 1e-3






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Tuple								=		self.scheduler_classes[0]
    SCREAMING_SNAKE_CASE  :  Dict								=		self.get_scheduler_config()
    SCREAMING_SNAKE_CASE  :  Any								=		scheduler_class(**__SCREAMING_SNAKE_CASE    ,use_karras_sigmas=__SCREAMING_SNAKE_CASE      )

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

    SCREAMING_SNAKE_CASE  :  List[Any]								=		self.dummy_model()
    SCREAMING_SNAKE_CASE  :  List[str]								=		self.dummy_sample_deter.to(__SCREAMING_SNAKE_CASE      ) * scheduler.init_noise_sigma
    SCREAMING_SNAKE_CASE  :  List[Any]								=		sample.to(__SCREAMING_SNAKE_CASE      )

    for t in scheduler.timesteps:
     SCREAMING_SNAKE_CASE  :  Dict								=		scheduler.scale_model_input(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  str								=		model(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )

     SCREAMING_SNAKE_CASE  :  Tuple								=		scheduler.step(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
     SCREAMING_SNAKE_CASE  :  List[Any]								=		output.prev_sample

    SCREAMING_SNAKE_CASE  :  Tuple								=		torch.sum(torch.abs(__SCREAMING_SNAKE_CASE      )      )
    SCREAMING_SNAKE_CASE  :  Tuple								=		torch.mean(torch.abs(__SCREAMING_SNAKE_CASE      )      )

    assert abs(result_sum.item() - 0.0_0015      ) < 1e-2
    assert abs(result_mean.item() - 1.9869_5545_3503_4695e-07      ) < 1e-2




'''simple docstring'''

def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	int   ,     snake_case_				:	list[tuple[int, int, int]]							)       ->	list[tuple[int, int, int]]:
 SCREAMING_SNAKE_CASE  :  List[Any]								=		sorted(snake_case_   ,     key=lambda snake_case_							: edge[2]							)

 SCREAMING_SNAKE_CASE  :  str								=		list(range(snake_case_							)							)

 def find_parent(snake_case_				:	Union[str, Any]							):
  if i != parent[i]:
   SCREAMING_SNAKE_CASE  :  int								=		find_parent(parent[i]							)
  return parent[i]

 SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		0
 SCREAMING_SNAKE_CASE  :  Any								=		[]

 for edge in edges:
  SCREAMING_SNAKE_CASE  :  Dict								=		find_parent(edge[0]							)
  SCREAMING_SNAKE_CASE  :  Optional[int]								=		find_parent(edge[1]							)
  if parent_a != parent_b:
   minimum_spanning_tree_cost += edge[2]
   minimum_spanning_tree.append(snake_case_							)
   SCREAMING_SNAKE_CASE  :  Tuple								=		parent_b

 return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
   __UpperCAmelCase						,						__UpperCAmelCase												=   list(map(int, input().strip().split()))
   __UpperCAmelCase												=   []

   for _ in range(num_edges):
      __UpperCAmelCase						,						__UpperCAmelCase						,						__UpperCAmelCase												=   (int(x) for x in input().strip().split())
      edges.append((nodea, nodea, cost))

   kruskal(num_nodes, edges)


