





import multiprocessing
import os
from typing import BinaryIO, Optional, Union

import fsspec

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.json.json import Json
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader



class    _a     (				lowercase__							):






							"""simple docstring"""

							def __init__(      self				:     Any							,	a				:     NestedDataStructureLike[PathLike]							,	a				:     Optional[NamedSplit] = None							,	a				:     Optional[Features] = None							,	a				:     str = None							,	a				:     bool = False							,	a				:     bool = False							,	a				:     Optional[str] = None							,	a				:     Optional[int] = None							,	**a				:     Tuple							,	)	->Any:
													super().__init__(
													    a							,	split=a							,	features=a							,	cache_dir=a							,	keep_in_memory=a							,	streaming=a							,	num_proc=a							,	**a							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					field
													SCREAMING_SNAKE_CASE__     :				int   =					path_or_paths if isinstance(a							,	a    ) else {self.split: path_or_paths}
													SCREAMING_SNAKE_CASE__     :				Tuple   =					Json(
													    cache_dir=a							,	data_files=a							,	features=a							,	field=a							,	**a							,	)






							def      A_  (      self				:     List[str]    )	->Any:
													# Build iterable dataset
													if self.streaming:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.builder.as_streaming_dataset(split=self.split    )
													# Build regular (map-style) dataset
													else:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					None
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					None
																			SCREAMING_SNAKE_CASE__     :				str   =					None
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					None

																			self.builder.download_and_prepare(
																			    download_config=a							,	download_mode=a							,	verification_mode=a							,	base_path=a							,	num_proc=self.num_proc							,	)
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					self.builder.as_dataset(
																			    split=self.split							,	verification_mode=a							,	in_memory=self.keep_in_memory    )
													return dataset







class    _a     :






							"""simple docstring"""

							def __init__(      self				:     Optional[Any]							,	a				:     Dataset							,	a				:     Union[PathLike, BinaryIO]							,	a				:     Optional[int] = None							,	a				:     Optional[int] = None							,	**a				:     Any							,	)	->Any:
													if num_proc is not None and num_proc <= 0:
																			raise ValueError(f"""num_proc {num_proc} must be an integer > 0."""    )

													SCREAMING_SNAKE_CASE__     :				Tuple   =					dataset
													SCREAMING_SNAKE_CASE__     :				List[str]   =					path_or_buf
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
													SCREAMING_SNAKE_CASE__     :				Any   =					num_proc
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					"utf-8"
													SCREAMING_SNAKE_CASE__     :				Any   =					to_json_kwargs

							def      A_  (      self				:     Union[str, Any]    )	->int:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					self.to_json_kwargs.pop("path_or_buf"							,	a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					self.to_json_kwargs.pop("orient"							,	"records"    )
													SCREAMING_SNAKE_CASE__     :				Any   =					self.to_json_kwargs.pop("lines"							,	True if orient == "records" else False    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.to_json_kwargs.pop("index"							,	False if orient in ["split", "table"] else True    )
													SCREAMING_SNAKE_CASE__     :				Any   =					self.to_json_kwargs.pop("compression"							,	a    )

													if compression not in [None, "infer", "gzip", "bz2", "xz"]:
																			raise NotImplementedError(f"""`datasets` currently does not support {compression} compression"""    )

													if isinstance(self.path_or_buf							,	(str, bytes, os.PathLike)    ):
																			with fsspec.open(self.path_or_buf							,	"wb"							,	compression=a    ) as buffer:
																									SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self._write(file_obj=a							,	orient=a							,	lines=a							,	index=a							,	**self.to_json_kwargs    )
													else:
																			if compression:
																									raise NotImplementedError(
																									    f"""The compression parameter is not supported when writing to a buffer, but compression={compression}"""
																									    " was passed. Please provide a local path instead."    )
																			SCREAMING_SNAKE_CASE__     :				Any   =					self._write(
																			    file_obj=self.path_or_buf							,	orient=a							,	lines=a							,	index=a							,	**self.to_json_kwargs    )
													return written

							def      A_  (      self				:     List[Any]							,	a				:     int    )	->str:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					args

													SCREAMING_SNAKE_CASE__     :				str   =					query_table(
													    table=self.dataset.data							,	key=slice(a							,	offset + self.batch_size    )							,	indices=self.dataset._indices							,	)
													SCREAMING_SNAKE_CASE__     :				Dict   =					batch.to_pandas().to_json(
													    path_or_buf=a							,	orient=a							,	lines=a							,	index=a							,	**a    )
													if not json_str.endswith("\n"    ):
																			json_str += "\n"
													return json_str.encode(self.encoding    )






							def      A_  (      self				:     str							,	a				:     BinaryIO							,	a				:     Optional[Any]							,	a				:     List[Any]							,	a				:     str							,	**a				:     Optional[int]							,	)	->int:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					0

													if self.num_proc is None or self.num_proc == 1:
																			for offset in logging.tqdm(
																			    range(0							,	len(self.dataset    )							,	self.batch_size    )							,	unit="ba"							,	disable=not logging.is_progress_bar_enabled()							,	desc="Creating json from Arrow format"							,	):
																									SCREAMING_SNAKE_CASE__     :				int   =					self._batch_json((offset, orient, lines, index, to_json_kwargs)    )
																									written += file_obj.write(a    )
													else:
																			SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					len(self.dataset    ), self.batch_size
																			with multiprocessing.Pool(self.num_proc    ) as pool:
																									for json_str in logging.tqdm(
																									    pool.imap(
																									        self._batch_json							,	[(offset, orient, lines, index, to_json_kwargs) for offset in range(0							,	a							,	a    )]							,	)							,	total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size							,	unit="ba"							,	disable=not logging.is_progress_bar_enabled()							,	desc="Creating json from Arrow format"							,	):
																															written += file_obj.write(a    )

													return written






import sys
from collections import defaultdict



class    _a     :






							"""simple docstring"""

							def __init__(      self				:     Any    )	->Dict:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					[]

							def      A_  (      self				:     int							,	a				:     List[str]    )	->Dict:
													return self.node_position[vertex]

							def      A_  (      self				:     Optional[Any]							,	a				:     Any							,	a				:     List[str]    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__     :				str   =					pos

							def      A_  (      self				:     List[Any]							,	a				:     List[str]							,	a				:     Dict							,	a				:     Dict							,	a				:     List[Any]    )	->Optional[int]:
													if start > size // 2 - 1:
																			return
													else:
																			if 2 * start + 2 >= size:
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					2 * start + 1
																			else:
																									if heap[2 * start + 1] < heap[2 * start + 2]:
																															SCREAMING_SNAKE_CASE__     :				Dict   =					2 * start + 1
																									else:
																															SCREAMING_SNAKE_CASE__     :				Tuple   =					2 * start + 2
																			if heap[smallest_child] < heap[start]:
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				int   =					heap[smallest_child], positions[smallest_child]
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					(
																									    heap[start],
																									    positions[start],
																									)
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					temp, tempa

																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					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      A_  (      self				:     Union[str, Any]							,	a				:     Tuple							,	a				:     Tuple							,	a				:     Union[str, Any]							,	a				:     List[Any]    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					position[index]

													while index != 0:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					int((index - 2) / 2    ) if index % 2 == 0 else int((index - 1) / 2    )

																			if val < heap[parent]:
																									SCREAMING_SNAKE_CASE__     :				List[Any]   =					heap[parent]
																									SCREAMING_SNAKE_CASE__     :				str   =					position[parent]
																									self.set_position(position[parent]							,	a    )
																			else:
																									SCREAMING_SNAKE_CASE__     :				int   =					val
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					temp
																									self.set_position(a							,	a    )
																									break
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					parent
													else:
																			SCREAMING_SNAKE_CASE__     :				int   =					val
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					temp
																			self.set_position(a							,	0    )

							def      A_  (      self				:     Union[str, Any]							,	a				:     int							,	a				:     List[str]    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					len(a    ) // 2 - 1
													for i in range(a							,	-1							,	-1    ):
																			self.top_to_bottom(a							,	a							,	len(a    )							,	a    )






							def      A_  (      self				:     Dict							,	a				:     List[Any]							,	a				:     Dict    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				Any   =					positions[0]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					sys.maxsize
													self.top_to_bottom(a							,	0							,	len(a    )							,	a    )
													return temp







def       UpperCAmelCase							(     _lowerCamelCase      :  str     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					Heap()

						SCREAMING_SNAKE_CASE__     :				Any   =					[0] * len(_lowerCamelCase     )
						SCREAMING_SNAKE_CASE__     :				Any   =					[-1] * len(_lowerCamelCase     )  # Neighboring Tree Vertex of selected vertex
						# Minimum Distance of explored vertex with neighboring vertex of partial tree
						# formed in graph
						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[]  # Heap of Distance of vertices from their neighboring vertex
						SCREAMING_SNAKE_CASE__     :				str   =					[]

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

						SCREAMING_SNAKE_CASE__     :				List[Any]   =					[]
						SCREAMING_SNAKE_CASE__     :				int   =					1
						SCREAMING_SNAKE_CASE__     :				int   =					sys.maxsize
						for neighbor, distance in adjacency_list[0]:
												SCREAMING_SNAKE_CASE__     :				int   =					0
												SCREAMING_SNAKE_CASE__     :				List[str]   =					distance
						heap.heapify(_lowerCamelCase			,   _lowerCamelCase     )

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


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