






'''simple docstring'''






import tempfile
import unittest

import numpy as np
import torch

from diffusers import DiffusionPipeline
from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor




class a_     (     unittest.TestCase				):







   def      SCREAMING_SNAKE_CASE__       (self       , __a = False)      ->   Any:
      """simple docstring"""






      __snake_case					:   int  				=			1_0

      if only_cross_attention:
         __snake_case					:   Optional[Any]  				=			1_2
      else:
         # when only cross attention is not set, the cross attention dim must be the same as the query dim
         __snake_case					:   Tuple  				=			query_dim

      return {
          "query_dim": query_dim,
          "cross_attention_dim": cross_attention_dim,
          "heads": 2,
          "dim_head": 4,
          "added_kv_proj_dim": 6,
          "norm_num_groups": 1,
          "only_cross_attention": only_cross_attention,
          "processor": AttnAddedKVProcessor(),
      }







   def      SCREAMING_SNAKE_CASE__       (self       , __a       , __a)      ->   List[str]:
      """simple docstring"""






      __snake_case					:   int  				=			2

      __snake_case					:   Tuple  				=			torch.rand(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE       , 3       , 2)
      __snake_case					:   int  				=			torch.rand(_SCREAMING_SNAKE_CASE       , 4       , _SCREAMING_SNAKE_CASE)
      __snake_case					:   Tuple  				=			None

      return {
          "hidden_states": hidden_states,
          "encoder_hidden_states": encoder_hidden_states,
          "attention_mask": attention_mask,
      }







   def      SCREAMING_SNAKE_CASE__       (self)      ->   List[Any]:
      """simple docstring"""






      torch.manual_seed(0)

      __snake_case					:   str  				=			self.get_constructor_arguments(only_cross_attention=_SCREAMING_SNAKE_CASE)
      __snake_case					:   int  				=			Attention(**_SCREAMING_SNAKE_CASE)

      self.assertTrue(attn.to_k is not None)
      self.assertTrue(attn.to_v is not None)

      __snake_case					:   List[str]  				=			self.get_forward_arguments(
          query_dim=constructor_args['query_dim']       , added_kv_proj_dim=constructor_args['added_kv_proj_dim'])

      __snake_case					:   Any  				=			attn(**_SCREAMING_SNAKE_CASE)

      # only self attention

      torch.manual_seed(0)

      __snake_case					:   Dict  				=			self.get_constructor_arguments(only_cross_attention=_SCREAMING_SNAKE_CASE)
      __snake_case					:   int  				=			Attention(**_SCREAMING_SNAKE_CASE)

      self.assertTrue(attn.to_k is None)
      self.assertTrue(attn.to_v is None)

      __snake_case					:   Optional[int]  				=			self.get_forward_arguments(
          query_dim=constructor_args['query_dim']       , added_kv_proj_dim=constructor_args['added_kv_proj_dim'])

      __snake_case					:   Union[str, Any]  				=			attn(**_SCREAMING_SNAKE_CASE)

      self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all())




class a_     (     unittest.TestCase				):







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Optional[int]:
      """simple docstring"""






      __snake_case					:   str  				=			DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe'       , safety_checker=_SCREAMING_SNAKE_CASE)

      __snake_case					:   str  				=			pipe(
          'foo'       , num_inference_steps=2       , generator=torch.Generator('cpu').manual_seed(0)       , output_type='np'       , ).images

      # the initial conversion succeeds
      __snake_case					:   str  				=			DiffusionPipeline.from_pretrained(
          'hf-internal-testing/tiny-stable-diffusion-pipe'       , device_map='sequential'       , safety_checker=_SCREAMING_SNAKE_CASE)

      __snake_case					:   str  				=			pipe(
          'foo'       , num_inference_steps=2       , generator=torch.Generator('cpu').manual_seed(0)       , output_type='np'       , ).images

      with tempfile.TemporaryDirectory() as tmpdir:
         # save the converted model
         pipe.save_pretrained(_SCREAMING_SNAKE_CASE)

         # can also load the converted weights
         __snake_case					:   Optional[Any]  				=			DiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE       , device_map='sequential'       , safety_checker=_SCREAMING_SNAKE_CASE)

      __snake_case					:   str  				=			pipe(
          'foo'       , num_inference_steps=2       , generator=torch.Generator('cpu').manual_seed(0)       , output_type='np'       , ).images

      self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE       , atol=1E-5))
      self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE       , atol=1E-5))

"""simple docstring"""







def        __lowerCAmelCase							(_UpperCamelCase			,    _UpperCamelCase						):
	__lowerCAmelCase     :		Any		     = sorted(_UpperCamelCase			,    key=lambda _UpperCamelCase						: edge[2]						)

	__lowerCAmelCase     :		Union[str, Any]		     = list(range(_UpperCamelCase						)						)

	def find_parent(_UpperCamelCase						):
		if i != parent[i]:
			__lowerCAmelCase     :		int		     = find_parent(parent[i]						)
		return parent[i]

	__lowerCAmelCase     :		Optional[Any]		     = 0
	__lowerCAmelCase     :		List[str]		     = []

	for edge in edges:
		__lowerCAmelCase     :		List[str]		     = find_parent(edge[0]						)
		__lowerCAmelCase     :		Optional[Any]		     = find_parent(edge[1]						)
		if parent_a != parent_b:
			minimum_spanning_tree_cost += edge[2]
			minimum_spanning_tree.append(_UpperCamelCase						)
			__lowerCAmelCase     :		Optional[Any]		     = parent_b

	return minimum_spanning_tree


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

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

							kruskal(num_nodes, edges)