


"""simple docstring"""


from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
	import PIL

A     :   Union[str, Any]			    =			logging.get_logger(__name__)


def _lowerCamelCase	(		_UpperCamelCase      ):

			'''simple docstring'''




			if isinstance(_UpperCamelCase    , (list, tuple)      ) and isinstance(videos[0]    , (list, tuple)      ) and is_valid_image(videos[0][0]      ):
						return videos

			elif isinstance(_UpperCamelCase    , (list, tuple)      ) and is_valid_image(videos[0]      ):
						return [videos]

			elif is_valid_image(_UpperCamelCase      ):
						return [[videos]]

			raise ValueError(f"Could not make batched video from {videos}"      )


class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							__UpperCAmelCase						:    List[str]				      =["""pixel_values"""]

							def __init__(     self    ,   __a = True    ,   __a = None    ,   __a = PILImageResampling.BILINEAR    ,   __a = True    ,   __a = None    ,   __a = True    ,   __a = 1 / 2_55    ,   __a = True    ,   __a = True    ,   __a = None    ,   __a = None    ,   **__a    ,   ):
										super().__init__(**__a	)
										__lowerCAmelCase				    =			size if size is not None else {"shortest_edge": 2_56}
										__lowerCAmelCase				    =			get_size_dict(__a    ,   default_to_square=__a	)
										__lowerCAmelCase				    =			crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
										__lowerCAmelCase				    =			get_size_dict(__a    ,   param_name="crop_size"	)

										__lowerCAmelCase				    =			do_resize
										__lowerCAmelCase				    =			size
										__lowerCAmelCase				    =			do_center_crop
										__lowerCAmelCase				    =			crop_size
										__lowerCAmelCase				    =			resample
										__lowerCAmelCase				    =			do_rescale
										__lowerCAmelCase				    =			rescale_factor
										__lowerCAmelCase				    =			offset
										__lowerCAmelCase				    =			do_normalize
										__lowerCAmelCase				    =			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
										__lowerCAmelCase				    =			image_std if image_std is not None else IMAGENET_STANDARD_STD

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a = PILImageResampling.BILINEAR    ,   __a = None    ,   **__a    ,   ):
										__lowerCAmelCase				    =			get_size_dict(__a    ,   default_to_square=__a	)
										if "shortest_edge" in size:
													__lowerCAmelCase				    =			get_resize_output_image_size(__a    ,   size["shortest_edge"]    ,   default_to_square=__a	)
										elif "height" in size and "width" in size:
													__lowerCAmelCase				    =			(size["height"], size["width"])
										else:
													raise ValueError(f"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"	)
										return resize(__a    ,   size=__a    ,   resample=__a    ,   data_format=__a    ,   **__a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a = None    ,   **__a    ,   ):
										__lowerCAmelCase				    =			get_size_dict(__a	)
										if "height" not in size or "width" not in size:
													raise ValueError(f"Size must have 'height' and 'width' as keys. Got {size.keys()}"	)
										return center_crop(__a    ,   size=(size["height"], size["width"])    ,   data_format=__a    ,   **__a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a = True    ,   __a = None    ,   **__a    ,   ):
										__lowerCAmelCase				    =			image.astype(np.floataa	)
										if offset:
													__lowerCAmelCase				    =			image - (scale / 2)
										return rescale(__a    ,   scale=__a    ,   data_format=__a    ,   **__a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a = None    ,   **__a    ,   ):
										return normalize(__a    ,   mean=__a    ,   std=__a    ,   data_format=__a    ,   **__a	)

							def 			snake_case				(     self    ,   __a    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = ChannelDimension.FIRST    ,   ):
										if do_resize and size is None or resample is None:
													raise ValueError("Size and resample must be specified if do_resize is True."	)

										if do_center_crop and crop_size is None:
													raise ValueError("Crop size must be specified if do_center_crop is True."	)

										if do_rescale and rescale_factor is None:
													raise ValueError("Rescale factor must be specified if do_rescale is True."	)

										if do_normalize and (image_mean is None or image_std is None):
													raise ValueError("Image mean and std must be specified if do_normalize is True."	)

										if offset and not do_rescale:
													raise ValueError("For offset, do_rescale must also be set to True."	)

										# All transformations expect numpy arrays.
										__lowerCAmelCase				    =			to_numpy_array(__a	)

										if do_resize:
													__lowerCAmelCase				    =			self.resize(image=__a    ,   size=__a    ,   resample=__a	)

										if do_center_crop:
													__lowerCAmelCase				    =			self.center_crop(__a    ,   size=__a	)

										if do_rescale:
													__lowerCAmelCase				    =			self.rescale(image=__a    ,   scale=__a    ,   offset=__a	)

										if do_normalize:
													__lowerCAmelCase				    =			self.normalize(image=__a    ,   mean=__a    ,   std=__a	)

										__lowerCAmelCase				    =			to_channel_dimension_format(__a    ,   __a	)
										return image



							def 			snake_case				(     self    ,   __a    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = None    ,   __a = ChannelDimension.FIRST    ,   **__a    ,   ):
										__lowerCAmelCase				    =			do_resize if do_resize is not None else self.do_resize
										__lowerCAmelCase				    =			resample if resample is not None else self.resample
										__lowerCAmelCase				    =			do_center_crop if do_center_crop is not None else self.do_center_crop
										__lowerCAmelCase				    =			do_rescale if do_rescale is not None else self.do_rescale
										__lowerCAmelCase				    =			rescale_factor if rescale_factor is not None else self.rescale_factor
										__lowerCAmelCase				    =			offset if offset is not None else self.offset
										__lowerCAmelCase				    =			do_normalize if do_normalize is not None else self.do_normalize
										__lowerCAmelCase				    =			image_mean if image_mean is not None else self.image_mean
										__lowerCAmelCase				    =			image_std if image_std is not None else self.image_std

										__lowerCAmelCase				    =			size if size is not None else self.size
										__lowerCAmelCase				    =			get_size_dict(__a    ,   default_to_square=__a	)
										__lowerCAmelCase				    =			crop_size if crop_size is not None else self.crop_size
										__lowerCAmelCase				    =			get_size_dict(__a    ,   param_name="crop_size"	)

										if not valid_images(__a	):
													raise ValueError(
													    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
													    "torch.Tensor, tf.Tensor or jax.ndarray."	)

										__lowerCAmelCase				    =			make_batched(__a	)

										__lowerCAmelCase				    =			[
										    [
										        self._preprocess_image(
										            image=__a    ,   do_resize=__a    ,   size=__a    ,   resample=__a    ,   do_center_crop=__a    ,   crop_size=__a    ,   do_rescale=__a    ,   rescale_factor=__a    ,   offset=__a    ,   do_normalize=__a    ,   image_mean=__a    ,   image_std=__a    ,   data_format=__a    ,   )
										        for img in video
										    ]
										    for video in videos
										]

										__lowerCAmelCase				    =			{"pixel_values": videos}
										return BatchFeature(data=__a    ,   tensor_type=__a	)








"""simple docstring"""


import sys
from collections import defaultdict
class   _UpperCamelCase  :
							'''simple docstring'''







							def __init__(     self	):
										__lowerCAmelCase				    =			[]

							def 			snake_case				(     self    ,   __a	):
										return self.node_position[vertex]

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			pos

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

																__lowerCAmelCase				    =			self.get_position(positions[smallest_child]	)
																self.set_position(
																    positions[smallest_child]    ,   self.get_position(positions[start]	)	)
																self.set_position(positions[start]    ,   __a	)

																self.top_to_bottom(__a    ,   __a    ,   __a    ,   __a	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			position[index]

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

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

							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			len(__a	) // 2 - 1
										for i in range(__a    ,   -1    ,   -1	):
													self.top_to_bottom(__a    ,   __a    ,   len(__a	)    ,   __a	)



							def 			snake_case				(     self    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			positions[0]
										__lowerCAmelCase				    =			sys.maxsize
										self.top_to_bottom(__a    ,   0    ,   len(__a	)    ,   __a	)
										return temp


def _lowerCamelCase	(		_UpperCamelCase      ):

			'''simple docstring'''




			__lowerCAmelCase				    =			Heap()

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

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

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

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


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




