






'''simple docstring'''







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

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




class 					__UpperCAmelCase (		_lowerCamelCase	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = None  ,		**_UpperCAmelCase  ,		):
             super().__init__(
                 _SCREAMING_SNAKE_CASE  ,		split=_SCREAMING_SNAKE_CASE  ,		features=_SCREAMING_SNAKE_CASE  ,		cache_dir=_SCREAMING_SNAKE_CASE  ,		keep_in_memory=_SCREAMING_SNAKE_CASE  ,		streaming=_SCREAMING_SNAKE_CASE  ,		num_proc=_SCREAMING_SNAKE_CASE  ,		**_SCREAMING_SNAKE_CASE  ,		)
             UpperCAmelCase__	:   List[str]												=	path_or_paths if isinstance(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE						) else {self.split: path_or_paths}
             UpperCAmelCase__	:   Any												=	Csv(
                 cache_dir=_SCREAMING_SNAKE_CASE  ,		data_files=_SCREAMING_SNAKE_CASE  ,		features=_SCREAMING_SNAKE_CASE  ,		**_SCREAMING_SNAKE_CASE  ,		)




      def 							lowerCamelCase     (					self						):
             # Build iterable dataset
             if self.streaming:
                    UpperCAmelCase__	:   Optional[Any]												=	self.builder.as_streaming_dataset(split=self.split						)
             # Build regular (map-style) dataset
             else:
                    UpperCAmelCase__	:   str												=	None
                    UpperCAmelCase__	:   int												=	None
                    UpperCAmelCase__	:   Optional[int]												=	None
                    UpperCAmelCase__	:   Optional[Any]												=	None

                    self.builder.download_and_prepare(
                        download_config=_SCREAMING_SNAKE_CASE  ,		download_mode=_SCREAMING_SNAKE_CASE  ,		verification_mode=_SCREAMING_SNAKE_CASE  ,		base_path=_SCREAMING_SNAKE_CASE  ,		num_proc=self.num_proc  ,		)
                    UpperCAmelCase__	:   int												=	self.builder.as_dataset(
                        split=self.split  ,		verification_mode=_SCREAMING_SNAKE_CASE  ,		in_memory=self.keep_in_memory						)
             return dataset




class 					__UpperCAmelCase :

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = None  ,		**_UpperCAmelCase  ,		):
             if num_proc is not None and num_proc <= 0:
                    raise ValueError(F"""num_proc {num_proc} must be an integer > 0."""						)

             UpperCAmelCase__	:   str												=	dataset
             UpperCAmelCase__	:   List[Any]												=	path_or_buf
             UpperCAmelCase__	:   Any												=	batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
             UpperCAmelCase__	:   Dict												=	num_proc
             UpperCAmelCase__	:   List[Any]												=	'utf-8'
             UpperCAmelCase__	:   Union[str, Any]												=	to_csv_kwargs




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	self.to_csv_kwargs.pop('''path_or_buf'''  ,		_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Optional[Any]												=	self.to_csv_kwargs.pop('''header'''  ,		_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Any												=	self.to_csv_kwargs.pop('''index'''  ,		_SCREAMING_SNAKE_CASE						)

             if isinstance(self.path_or_buf  ,		(str, bytes, os.PathLike)						):
                    with open(self.path_or_buf  ,		'''wb+'''						) as buffer:
                           UpperCAmelCase__	:   Union[str, Any]												=	self._write(file_obj=_SCREAMING_SNAKE_CASE  ,		header=_SCREAMING_SNAKE_CASE  ,		index=_SCREAMING_SNAKE_CASE  ,		**self.to_csv_kwargs						)
             else:
                    UpperCAmelCase__	:   Dict												=	self._write(file_obj=self.path_or_buf  ,		header=_SCREAMING_SNAKE_CASE  ,		index=_SCREAMING_SNAKE_CASE  ,		**self.to_csv_kwargs						)
             return written




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             UpperCAmelCase__	:   Union[str, Any]												=	args

             UpperCAmelCase__	:   Dict												=	query_table(
                 table=self.dataset.data  ,		key=slice(_SCREAMING_SNAKE_CASE  ,		offset + self.batch_size						)  ,		indices=self.dataset._indices  ,		)
             UpperCAmelCase__	:   Union[str, Any]												=	batch.to_pandas().to_csv(
                 path_or_buf=_SCREAMING_SNAKE_CASE  ,		header=header if (offset == 0) else False  ,		index=_SCREAMING_SNAKE_CASE  ,		**_SCREAMING_SNAKE_CASE						)
             return csv_str.encode(self.encoding						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		**_UpperCAmelCase						):
             UpperCAmelCase__	:   Optional[Any]												=	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 CSV from Arrow format'''  ,		):
                           UpperCAmelCase__	:   Tuple												=	self._batch_csv((offset, header, index, to_csv_kwargs)						)
                           written += file_obj.write(_SCREAMING_SNAKE_CASE						)

             else:
                    UpperCAmelCase__	:   Optional[int]												=	len(self.dataset						), self.batch_size
                    with multiprocessing.Pool(self.num_proc						) as pool:
                           for csv_str in logging.tqdm(
                               pool.imap(
                                   self._batch_csv  ,		[(offset, header, index, to_csv_kwargs) for offset in range(0  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE						)]  ,		)  ,		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 CSV from Arrow format'''  ,		):
                                  written += file_obj.write(_SCREAMING_SNAKE_CASE						)

             return written

"""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)