import os
import warnings
from pathlib import Path
from typing import Optional, Union

from .dynamic_module_utils import custom_object_save
from .tokenization_utils_base import PreTrainedTokenizerBase
from .utils import PushToHubMixin, copy_func, direct_transformers_import, logging


__snake_case			      =    logging.get_logger(__name__)

# Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
__snake_case			      =    direct_transformers_import(Path(__file__).parent)


__snake_case			      =    {
    '''AutoTokenizer''': '''PreTrainedTokenizerBase''',
    '''AutoFeatureExtractor''': '''FeatureExtractionMixin''',
    '''AutoImageProcessor''': '''ImageProcessingMixin''',
}







class 			__snake_case   (     lowerCamelCase__   ):
 __lowerCamelCase    :   Any     =      ["""feature_extractor""", """tokenizer"""]
 # Names need to be attr_class for attr in attributes
 __lowerCamelCase    :   Optional[Any]     =      None
 __lowerCamelCase    :   Tuple     =      None
 __lowerCamelCase    :   Union[str, Any]     =      None
 def __init__(  self		,   *snake_case__		,   **snake_case__						)	->							Optional[Any]:
       '''simple docstring'''





       for key in kwargs:
             if key not in self.attributes:
                   raise TypeError(f'''Unexpected keyword argument {key}.'''						)
       for arg, attribute_name in zip(snake_case__		,   self.attributes						):
             if attribute_name in kwargs:
                   raise TypeError(f'''Got multiple values for argument {attribute_name}.'''						)
             else:
                   UpperCAmelCase    : Optional[int]      =arg

       if len(snake_case__						) != len(self.attributes						):
             raise ValueError(
                 f'''This processor requires {len(self.attributes						)} arguments: {', '.join(self.attributes						)}. Got '''
                 f'''{len(snake_case__						)} arguments instead.'''						)

       # Check each arg is of the proper class (this will also catch a user initializing in the wrong order)
       for attribute_name, arg in kwargs.items():
             UpperCAmelCase    : str      =getattr(self		,   f'''{attribute_name}_class'''						)
             # Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
             UpperCAmelCase    : str      =AUTO_TO_BASE_CLASS_MAPPING.get(snake_case__		,   snake_case__						)
             if isinstance(snake_case__		,   snake_case__						):
                   UpperCAmelCase    : Optional[int]      =tuple(getattr(snake_case__		,   snake_case__						) for n in class_name if n is not None						)
             else:
                   UpperCAmelCase    : List[str]      =getattr(snake_case__		,   snake_case__						)

             if not isinstance(snake_case__		,   snake_case__						):
                   raise ValueError(
                       f'''Received a {type(snake_case__						).__name__} for argument {attribute_name}, but a {class_name} was expected.'''						)

             setattr(self		,   snake_case__		,   snake_case__						)
 def __repr__(  self						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =[f'''- {name}: {repr(getattr(self		,   snake_case__						)						)}''' for name in self.attributes]
       UpperCAmelCase    : int      ='''\n'''.join(snake_case__						)
       return f'''{self.__class__.__name__}:\n{attributes_repr}'''
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__ = False		,   **snake_case__						)	->							Any:
       '''simple docstring'''





       os.makedirs(snake_case__		,   exist_ok=snake_case__						)

       if push_to_hub:
             UpperCAmelCase    : Optional[Any]      =kwargs.pop('''commit_message'''		,   snake_case__						)
             UpperCAmelCase    : Any      =kwargs.pop('''repo_id'''		,   save_directory.split(os.path.sep						)[-1]						)
             UpperCAmelCase    : Any      =self._create_repo(snake_case__		,   **snake_case__						)
             UpperCAmelCase    : Any      =self._get_files_timestamps(snake_case__						)
       # If we have a custom config, we copy the file defining it in the folder and set the attributes so it can be
       # loaded from the Hub.
       if self._auto_class is not None:
             UpperCAmelCase    : Any      =[getattr(self		,   snake_case__						) for attribute_name in self.attributes]
             UpperCAmelCase    : int      =[(a.init_kwargs if isinstance(snake_case__		,   snake_case__						) else a) for a in attrs]
             custom_object_save(self		,   snake_case__		,   config=snake_case__						)

       for attribute_name in self.attributes:
             UpperCAmelCase    : str      =getattr(self		,   snake_case__						)
             # Include the processor class in the attribute config so this processor can then be reloaded with the
             # `AutoProcessor` API.
             if hasattr(snake_case__		,   '''_set_processor_class'''						):
                   attribute._set_processor_class(self.__class__.__name__						)
             attribute.save_pretrained(snake_case__						)

       if self._auto_class is not None:
             # We added an attribute to the init_kwargs of the tokenizers, which needs to be cleaned up.
             for attribute_name in self.attributes:
                   UpperCAmelCase    : Optional[Any]      =getattr(self		,   snake_case__						)
                   if isinstance(snake_case__		,   snake_case__						):
                         del attribute.init_kwargs["auto_map"]

       if push_to_hub:
             self._upload_modified_files(
                 snake_case__		,   snake_case__		,   snake_case__		,   commit_message=snake_case__		,   token=kwargs.get('''use_auth_token'''						)		,   )
 @classmethod
 def 	UpperCAmelCase__       (  cls		,   snake_case__		,   snake_case__ = None		,   snake_case__ = False		,   snake_case__ = False		,   snake_case__ = None		,   snake_case__ = "main"		,   **snake_case__		,   )	->							Optional[Any]:
       '''simple docstring'''





       UpperCAmelCase    : Any      =cache_dir
       UpperCAmelCase    : str      =force_download
       UpperCAmelCase    : Any      =local_files_only
       UpperCAmelCase    : Tuple      =revision

       UpperCAmelCase    : Any      =kwargs.pop('''use_auth_token'''		,   snake_case__						)
       if use_auth_token is not None:
             warnings.warn(
                 '''The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.'''		,   snake_case__						)
             if token is not None:
                   raise ValueError(
                       '''`token` and `use_auth_token` are both specified. Please set only the argument `token`.'''						)
             UpperCAmelCase    : Dict      =use_auth_token

       if token is not None:
             # change to `token` in a follow-up PR
             UpperCAmelCase    : Optional[int]      =token

       UpperCAmelCase    : Dict      =cls._get_arguments_from_pretrained(snake_case__		,   **snake_case__						)
       return cls(*snake_case__						)
 @classmethod
 def 	UpperCAmelCase__       (  cls		,   snake_case__="AutoProcessor"						)	->							int:
       '''simple docstring'''





       if not isinstance(snake_case__		,   snake_case__						):
             UpperCAmelCase    : List[str]      =auto_class.__name__

       import transformers.models.auto as auto_module

       if not hasattr(snake_case__		,   snake_case__						):
             raise ValueError(f'''{auto_class} is not a valid auto class.'''						)

       UpperCAmelCase    : List[Any]      =auto_class
 @classmethod
 def 	UpperCAmelCase__       (  cls		,   snake_case__		,   **snake_case__						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =[]
       for attribute_name in cls.attributes:
             UpperCAmelCase    : Optional[Any]      =getattr(cls		,   f'''{attribute_name}_class'''						)
             if isinstance(snake_case__		,   snake_case__						):
                   UpperCAmelCase    : List[Any]      =tuple(getattr(snake_case__		,   snake_case__						) if n is not None else None for n in class_name						)
                   UpperCAmelCase    : List[Any]      =kwargs.get('''use_fast'''		,   snake_case__						)
                   if use_fast and classes[1] is not None:
                         UpperCAmelCase    : Optional[int]      =classes[1]
                   else:
                         UpperCAmelCase    : Optional[int]      =classes[0]
             else:
                   UpperCAmelCase    : List[Any]      =getattr(snake_case__		,   snake_case__						)

             args.append(attribute_class.from_pretrained(snake_case__		,   **snake_case__						)						)
       return args






 @property
 def 	UpperCAmelCase__       (  self						)	->							int:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =getattr(self		,   self.attributes[0]						)
       return getattr(snake_case__		,   '''model_input_names'''		,   snake_case__						)



__snake_case			      =    copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
     __snake_case			      =    ProcessorMixin.push_to_hub.__doc__.format(
         object='''processor''', object_class='''AutoProcessor''', object_files='''processor files'''
     )

def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase						)->  list[tuple[int, int, int]]:






      '''simple docstring'''





      UpperCAmelCase    : List[Any]      =sorted(__lowerCAmelCase		,					key=lambda __lowerCAmelCase						: edge[2]						)

      UpperCAmelCase    : Union[str, Any]      =list(range(__lowerCAmelCase						)						)

      def find_parent(__lowerCAmelCase						):
            if i != parent[i]:
                  UpperCAmelCase    : Optional[int]      =find_parent(parent[i]						)
            return parent[i]

      UpperCAmelCase    : Optional[Any]      =0
      UpperCAmelCase    : List[str]      =[]

      for edge in edges:
            UpperCAmelCase    : Dict      =find_parent(edge[0]						)
            UpperCAmelCase    : Optional[Any]      =find_parent(edge[1]						)
            if parent_a != parent_b:
                  minimum_spanning_tree_cost += edge[2]
                  minimum_spanning_tree.append(__lowerCAmelCase						)
                  UpperCAmelCase    : Optional[Any]      =parent_b

      return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
     __snake_case      ,  __snake_case			      =    list(map(int, input().strip().split()))
     __snake_case			      =    []

     for _ in range(num_edges):
          __snake_case      ,  __snake_case      ,  __snake_case			      =    (int(x) for x in input().strip().split())
          edges.append((nodea, nodea, cost))

     kruskal(num_nodes, edges)
