






"""simple docstring"""





import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
  import jax
  import jax.numpy as jnp
  from flax.jax_utils import replicate
  from flax.training.common_utils import shard
@slow
@require_flax
class    __lowerCamelCase    (  unittest.TestCase  ):

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
       UpperCamelCase__       ,						UpperCamelCase__         =    FlaxStableDiffusionPipeline.from_pretrained(
           'stabilityai/stable-diffusion-2' ,				revision='bf16' ,				dtype=jnp.bfloataa ,				)

       UpperCamelCase__         =    'A painting of a squirrel eating a burger'
       UpperCamelCase__         =    jax.device_count()
       UpperCamelCase__         =    num_samples * [prompt]
       UpperCamelCase__         =    sd_pipe.prepare_inputs(snake_case_      )

       UpperCamelCase__         =    replicate(snake_case_      )
       UpperCamelCase__         =    shard(snake_case_      )

       UpperCamelCase__         =    jax.random.PRNGKey(0      )
       UpperCamelCase__         =    jax.random.split(snake_case_ ,				jax.device_count()      )

       UpperCamelCase__         =    sd_pipe(snake_case_ ,				snake_case_ ,				snake_case_ ,				num_inference_steps=25 ,				jit=snake_case_      )[0]
       assert images.shape == (jax.device_count(), 1, 768, 768, 3)

       UpperCamelCase__         =    images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]      )
       UpperCamelCase__         =    images[0, 253:256, 253:256, -1]

       UpperCamelCase__         =    jnp.asarray(jax.device_get(image_slice.flatten()      )      )
       UpperCamelCase__         =    jnp.array([0.4_238, 0.4_414, 0.4_395, 0.4_453, 0.4_629, 0.4_590, 0.4_531, 0.45_508, 0.4_512]      )
       print(F'output_slice: {output_slice}'      )
       assert jnp.abs(output_slice - expected_slice      ).max() < 1E-2







   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[Any]:
       UpperCamelCase__         =    'stabilityai/stable-diffusion-2'
       UpperCamelCase__       ,						UpperCamelCase__         =    FlaxDPMSolverMultistepScheduler.from_pretrained(snake_case_ ,				subfolder='scheduler'      )
       UpperCamelCase__       ,						UpperCamelCase__         =    FlaxStableDiffusionPipeline.from_pretrained(
           snake_case_ ,				scheduler=snake_case_ ,				revision='bf16' ,				dtype=jnp.bfloataa ,				)
       UpperCamelCase__         =    scheduler_params

       UpperCamelCase__         =    'A painting of a squirrel eating a burger'
       UpperCamelCase__         =    jax.device_count()
       UpperCamelCase__         =    num_samples * [prompt]
       UpperCamelCase__         =    sd_pipe.prepare_inputs(snake_case_      )

       UpperCamelCase__         =    replicate(snake_case_      )
       UpperCamelCase__         =    shard(snake_case_      )

       UpperCamelCase__         =    jax.random.PRNGKey(0      )
       UpperCamelCase__         =    jax.random.split(snake_case_ ,				jax.device_count()      )

       UpperCamelCase__         =    sd_pipe(snake_case_ ,				snake_case_ ,				snake_case_ ,				num_inference_steps=25 ,				jit=snake_case_      )[0]
       assert images.shape == (jax.device_count(), 1, 768, 768, 3)

       UpperCamelCase__         =    images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]      )
       UpperCamelCase__         =    images[0, 253:256, 253:256, -1]

       UpperCamelCase__         =    jnp.asarray(jax.device_get(image_slice.flatten()      )      )
       UpperCamelCase__         =    jnp.array([0.4_336, 0.42_969, 0.4_453, 0.4_199, 0.4_297, 0.4_531, 0.4_434, 0.4_434, 0.4_297]      )
       print(F'output_slice: {output_slice}'      )
       assert jnp.abs(output_slice - expected_slice      ).max() < 1E-2












"""simple docstring"""





import sys
from collections import defaultdict
class    __lowerCamelCase    :

   def __init__(					self      )		->       Tuple:
       UpperCamelCase__         =    []

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_      )		->       List[str]:
       return self.node_position[vertex]

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_      )		->       Optional[int]:
       UpperCamelCase__         =    pos

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       List[Any]:
       if start > size // 2 - 1:
           return
       else:
           if 2 * start + 2 >= size:
               UpperCamelCase__         =    2 * start + 1
           else:
               if heap[2 * start + 1] < heap[2 * start + 2]:
                   UpperCamelCase__         =    2 * start + 1
               else:
                   UpperCamelCase__         =    2 * start + 2
           if heap[smallest_child] < heap[start]:
               UpperCamelCase__       ,						UpperCamelCase__         =    heap[smallest_child], positions[smallest_child]
               UpperCamelCase__       ,						UpperCamelCase__         =    (
                   heap[start],
                   positions[start],
               )
               UpperCamelCase__       ,						UpperCamelCase__         =    temp, tempa

               UpperCamelCase__         =    self.get_position(positions[smallest_child]      )
               self.set_position(
                   positions[smallest_child] ,				self.get_position(positions[start]      )      )
               self.set_position(positions[start] ,				snake_case_      )

               self.top_to_bottom(snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       Any:
       UpperCamelCase__         =    position[index]

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

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

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_      )		->       Any:
       UpperCamelCase__         =    len(snake_case_      ) // 2 - 1
       for i in range(snake_case_ ,				-1 ,				-1      ):
           self.top_to_bottom(snake_case_ ,				snake_case_ ,				len(snake_case_      ) ,				snake_case_      )







   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_      )		->       List[Any]:
       UpperCamelCase__         =    positions[0]
       UpperCamelCase__         =    sys.maxsize
       self.top_to_bottom(snake_case_ ,				0 ,				len(snake_case_      ) ,				snake_case_      )
       return temp







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	Tuple:
    """simple docstring"""

    UpperCamelCase__         =    Heap()

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

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

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

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


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




