


'''simple docstring'''




from __future__ import annotations

from typing import Any




class 			_lowercase :
   def __init__(						self       :      Any       ,   SCREAMING_SNAKE_CASE_       :      int      ) ->							None:
        __snake_case           =						num_of_nodes
        __snake_case           =						[]
        __snake_case           =						{}
   def a  (						self       :      List[Any]       ,   SCREAMING_SNAKE_CASE_       :      int       ,   SCREAMING_SNAKE_CASE_       :      int       ,   SCREAMING_SNAKE_CASE_       :      int      ) ->							None:
        self.m_edges.append([u_node, v_node, weight]      )
   def a  (						self       :      str       ,   SCREAMING_SNAKE_CASE_       :      int      ) ->							int:

        if self.m_component[u_node] == u_node:
             return u_node
        return self.find_component(self.m_component[u_node]      )
   def a  (						self       :      Union[str, Any]       ,   SCREAMING_SNAKE_CASE_       :      int      ) ->							None:

        if self.m_component[u_node] != u_node:
             for k in self.m_component:
                  __snake_case           =						self.find_component(SCREAMING_SNAKE_CASE_      )
   def a  (						self       :      Tuple       ,   SCREAMING_SNAKE_CASE_       :      list[int]       ,   SCREAMING_SNAKE_CASE_       :      int       ,   SCREAMING_SNAKE_CASE_       :      int      ) ->							None:

        if component_size[u_node] <= component_size[v_node]:
             __snake_case           =						v_node
             component_size[v_node] += component_size[u_node]
             self.set_component(SCREAMING_SNAKE_CASE_      )

        elif component_size[u_node] >= component_size[v_node]:
             __snake_case           =						self.find_component(SCREAMING_SNAKE_CASE_      )
             component_size[u_node] += component_size[v_node]
             self.set_component(SCREAMING_SNAKE_CASE_      )





   def a  (						self       :      Any      ) ->							None:
        __snake_case           =						[]
        __snake_case           =						0

        __snake_case           =						[-1] * self.m_num_of_nodes

        # A list of components (initialized to all of the nodes)
        for node in range(self.m_num_of_nodes      ):
             self.m_component.update({node: node}      )
             component_size.append(1      )

        __snake_case           =						self.m_num_of_nodes

        while num_of_components > 1:
             for edge in self.m_edges:
                  __snake_case      ,       __snake_case      ,       __snake_case           =						edge

                  __snake_case           =						self.m_component[u]
                  __snake_case           =						self.m_component[v]

                  if u_component != v_component:

                       for component in (u_component, v_component):
                            if (
                                minimum_weight_edge[component] == -1
                                or minimum_weight_edge[component][2] > w
                            ):
                                 __snake_case           =						[u, v, w]

             for edge in minimum_weight_edge:
                  if isinstance(SCREAMING_SNAKE_CASE_       ,   SCREAMING_SNAKE_CASE_      ):
                       __snake_case      ,       __snake_case      ,       __snake_case           =						edge

                       __snake_case           =						self.m_component[u]
                       __snake_case           =						self.m_component[v]

                       if u_component != v_component:
                            mst_weight += w
                            self.union(SCREAMING_SNAKE_CASE_       ,   SCREAMING_SNAKE_CASE_       ,   SCREAMING_SNAKE_CASE_      )
                            print(f'Added edge [{u} - {v}]\nAdded weight: {w}\n'      )
                            num_of_components -= 1

             __snake_case           =						[-1] * self.m_num_of_nodes
        print(f'The total weight of the minimal spanning tree is: {mst_weight}'      )





def   _a		()			->			None:






     """simple docstring"""


if __name__ == "__main__":
       import doctest

       doctest.testmod()






"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_lowercase				 =					{
    '''configuration_electra''': ['''ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ElectraConfig''', '''ElectraOnnxConfig'''],
    '''tokenization_electra''': ['''ElectraTokenizer'''],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					['''ElectraTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ElectraForCausalLM''',
		    '''ElectraForMaskedLM''',
		    '''ElectraForMultipleChoice''',
		    '''ElectraForPreTraining''',
		    '''ElectraForQuestionAnswering''',
		    '''ElectraForSequenceClassification''',
		    '''ElectraForTokenClassification''',
		    '''ElectraModel''',
		    '''ElectraPreTrainedModel''',
		    '''load_tf_weights_in_electra''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFElectraForMaskedLM''',
		    '''TFElectraForMultipleChoice''',
		    '''TFElectraForPreTraining''',
		    '''TFElectraForQuestionAnswering''',
		    '''TFElectraForSequenceClassification''',
		    '''TFElectraForTokenClassification''',
		    '''TFElectraModel''',
		    '''TFElectraPreTrainedModel''',
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''FlaxElectraForCausalLM''',
		    '''FlaxElectraForMaskedLM''',
		    '''FlaxElectraForMultipleChoice''',
		    '''FlaxElectraForPreTraining''',
		    '''FlaxElectraForQuestionAnswering''',
		    '''FlaxElectraForSequenceClassification''',
		    '''FlaxElectraForTokenClassification''',
		    '''FlaxElectraModel''',
		    '''FlaxElectraPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
		from .tokenization_electra import ElectraTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_electra_fast import ElectraTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_electra import (
				    ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ElectraForCausalLM,
				    ElectraForMaskedLM,
				    ElectraForMultipleChoice,
				    ElectraForPreTraining,
				    ElectraForQuestionAnswering,
				    ElectraForSequenceClassification,
				    ElectraForTokenClassification,
				    ElectraModel,
				    ElectraPreTrainedModel,
				    load_tf_weights_in_electra,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_electra import (
				    TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFElectraForMaskedLM,
				    TFElectraForMultipleChoice,
				    TFElectraForPreTraining,
				    TFElectraForQuestionAnswering,
				    TFElectraForSequenceClassification,
				    TFElectraForTokenClassification,
				    TFElectraModel,
				    TFElectraPreTrainedModel,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_electra import (
				    FlaxElectraForCausalLM,
				    FlaxElectraForMaskedLM,
				    FlaxElectraForMultipleChoice,
				    FlaxElectraForPreTraining,
				    FlaxElectraForQuestionAnswering,
				    FlaxElectraForSequenceClassification,
				    FlaxElectraForTokenClassification,
				    FlaxElectraModel,
				    FlaxElectraPreTrainedModel,
				)

else:
		import sys

		_lowercase				 =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)