
"""simple docstring"""







import importlib
import inspect
from functools import wraps
from typing import TYPE_CHECKING, Optional, Union

from .download.streaming_download_manager import (
    xbasename,
    xdirname,
    xet_parse,
    xexists,
    xgetsize,
    xglob,
    xgzip_open,
    xisdir,
    xisfile,
    xjoin,
    xlistdir,
    xnumpy_load,
    xopen,
    xpandas_read_csv,
    xpandas_read_excel,
    xPath,
    xrelpath,
    xsio_loadmat,
    xsplit,
    xsplitext,
    xwalk,
    xxml_dom_minidom_parse,
)
from .utils.logging import get_logger
from .utils.patching import patch_submodule
from .utils.py_utils import get_imports


lowerCamelCase__     =						get_logger(__name__)


if TYPE_CHECKING:
							from .builder import DatasetBuilder
def        __lowerCAmelCase							(_UpperCamelCase			,    _UpperCamelCase = None						):
	__lowerCAmelCase     :		Union[str, Any]		     = importlib.import_module(_UpperCamelCase						)

	# TODO(QL): always update the module to add subsequent new authentication
	if hasattr(_UpperCamelCase			,    '_patched_for_streaming'						) and module._patched_for_streaming:
		return

	def wrap_auth(_UpperCamelCase						):
		@wraps(_UpperCamelCase						)
		def wrapper(*_UpperCamelCase			,    **_UpperCamelCase						):
			return function(*_UpperCamelCase			,    use_auth_token=_UpperCamelCase			,    **_UpperCamelCase						)

		__lowerCAmelCase     :		Optional[int]		     = 'wrap_auth'
		return wrapper

	# open files in a streaming fashion
	patch_submodule(_UpperCamelCase			,    'open'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'os.listdir'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'os.walk'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'glob.glob'			,    wrap_auth(_UpperCamelCase						)						).start()
	# allow to navigate in remote zip files
	patch_submodule(_UpperCamelCase			,    'os.path.join'			,    _UpperCamelCase						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.dirname'			,    _UpperCamelCase						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.basename'			,    _UpperCamelCase						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.relpath'			,    _UpperCamelCase						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.split'			,    _UpperCamelCase						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.splitext'			,    _UpperCamelCase						).start()
	# allow checks on paths
	patch_submodule(_UpperCamelCase			,    'os.path.exists'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.isdir'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.isfile'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'os.path.getsize'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'pathlib.Path'			,    _UpperCamelCase						).start()
	# file readers
	patch_submodule(_UpperCamelCase			,    'gzip.open'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'numpy.load'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'pandas.read_csv'			,    wrap_auth(_UpperCamelCase						)			,    attrs=['__version__']						).start()
	patch_submodule(_UpperCamelCase			,    'pandas.read_excel'			,    wrap_auth(_UpperCamelCase						)			,    attrs=['__version__']						).start()
	patch_submodule(_UpperCamelCase			,    'scipy.io.loadmat'			,    wrap_auth(_UpperCamelCase						)			,    attrs=['__version__']						).start()
	patch_submodule(_UpperCamelCase			,    'xml.etree.ElementTree.parse'			,    wrap_auth(_UpperCamelCase						)						).start()
	patch_submodule(_UpperCamelCase			,    'xml.dom.minidom.parse'			,    wrap_auth(_UpperCamelCase						)						).start()
	__lowerCAmelCase     :		Tuple		     = True
def        __lowerCAmelCase							(_UpperCamelCase						):
	extend_module_for_streaming(builder.__module__			,    use_auth_token=builder.use_auth_token						)
	# if needed, we also have to extend additional internal imports (like wmt14 -> wmt_utils)
	if not builder.__module__.startswith('datasets.'						):  # check that it's not a packaged builder like csv
		for imports in get_imports(inspect.getfile(builder.__class__						)						):
			if imports[0] == "internal":
				__lowerCAmelCase     :		Optional[Any]		     = imports[1]
				__lowerCAmelCase     :		Optional[Any]		     = '.'.join(builder.__module__.split('.'						)[:-1] + [internal_import_name]						)
				extend_module_for_streaming(_UpperCamelCase			,    use_auth_token=builder.use_auth_token						)

    # builders can inherit from other builders that might use streaming functionality
    # (for example, ImageFolder and AudioFolder inherit from FolderBuilder which implements examples generation)
    # but these parents builders are not patched automatically as they are not instantiated, so we patch them here
	from .builder import DatasetBuilder

	__lowerCAmelCase     :		Tuple		     = [
	    cls.__module__
	    for cls in type(_UpperCamelCase						).__mro__[1:]  # make sure it's not the same module we've already patched
	    if issubclass(cls			,    _UpperCamelCase						) and cls.__module__ != DatasetBuilder.__module__
	]  # check it's not a standard builder from datasets.builder
	for module in parent_builder_modules:
		extend_module_for_streaming(_UpperCamelCase			,    use_auth_token=builder.use_auth_token						)

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