


"""simple docstring"""






from __future__ import annotations

from typing import Any


class     __lowerCamelCase  :

     '''simple docstring'''


     def __init__(      self    ,				__UpperCAmelCase							)       ->							None:
          _a    	=				num_of_nodes
          _a    	=				[]
          _a    	=				{}


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase							)       ->							None:
          self.m_edges.append([u_node, v_node, weight]							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							int:

          if self.m_component[u_node] == u_node:
               return u_node
          return self.find_component(self.m_component[u_node]							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							None:

          if self.m_component[u_node] != u_node:
               for k in self.m_component:
                    _a    	=				self.find_component(__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase							)       ->							None:

          if component_size[u_node] <= component_size[v_node]:
               _a    	=				v_node
               component_size[v_node] += component_size[u_node]
               self.set_component(__UpperCAmelCase							)

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





     def 							_UpperCAmelCase      (      self							)       ->							None:
          _a    	=				[]
          _a    	=				0

          _a    	=				[-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							)

          _a    	=				self.m_num_of_nodes

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

                    _a    	=				self.m_component[u]
                    _a    	=				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
                              ):
                                   _a    	=				[u, v, w]

               for edge in minimum_weight_edge:
                    if isinstance(__UpperCAmelCase    ,				__UpperCAmelCase							):
                         _a	,      _a	,      _a    	=				edge

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

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

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







def       A_   (   ):






     """simple docstring"""



if __name__ == "__main__":
   import doctest

   doctest.testmod()



"""simple docstring"""






from typing import TYPE_CHECKING

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


__snake_case		=       {
    '''configuration_lxmert''': ['''LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''LxmertConfig'''],
    '''tokenization_lxmert''': ['''LxmertTokenizer'''],
}

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

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __snake_case		=       [
       '''LxmertEncoder''',
       '''LxmertForPreTraining''',
       '''LxmertForQuestionAnswering''',
       '''LxmertModel''',
       '''LxmertPreTrainedModel''',
       '''LxmertVisualFeatureEncoder''',
       '''LxmertXLayer''',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __snake_case		=       [
       '''TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''TFLxmertForPreTraining''',
       '''TFLxmertMainLayer''',
       '''TFLxmertModel''',
       '''TFLxmertPreTrainedModel''',
       '''TFLxmertVisualFeatureEncoder''',
   ]


if TYPE_CHECKING:
   from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
   from .tokenization_lxmert import LxmertTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_lxmert_fast import LxmertTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_lxmert import (
          LxmertEncoder,
          LxmertForPreTraining,
          LxmertForQuestionAnswering,
          LxmertModel,
          LxmertPreTrainedModel,
          LxmertVisualFeatureEncoder,
          LxmertXLayer,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_lxmert import (
          TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFLxmertForPreTraining,
          TFLxmertMainLayer,
          TFLxmertModel,
          TFLxmertPreTrainedModel,
          TFLxmertVisualFeatureEncoder,
      )

else:
   import sys

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