


from __future__ import annotations

from typing import Any



class        A     :







     '''simple docstring'''







     def __init__(				self    :							Any			,				_UpperCamelCase    :							int):
      _lowercase:       str						=				num_of_nodes
      _lowercase:       list[list[int]]						=				[]
      _lowercase:       dict[int, int]						=				{}

     def 					UpperCAmelCase__       (				self    :							Tuple			,				_UpperCamelCase    :							int			,				_UpperCamelCase    :							int			,				_UpperCamelCase    :							int):
      self.m_edges.append([u_node, v_node, weight])

     def 					UpperCAmelCase__       (				self    :							Tuple			,				_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    :							Tuple			,				_UpperCamelCase    :							int):

      if self.m_component[u_node] != u_node:
       for k in self.m_component:
        _lowercase:       Optional[int]						=				self.find_component(_UpperCamelCase)

     def 					UpperCAmelCase__       (				self    :							Optional[int]			,				_UpperCamelCase    :							list[int]			,				_UpperCamelCase    :							int			,				_UpperCamelCase    :							int):

      if component_size[u_node] <= component_size[v_node]:
       _lowercase:       Union[str, Any]						=				v_node
       component_size[v_node] += component_size[u_node]
       self.set_component(_UpperCamelCase)

      elif component_size[u_node] >= component_size[v_node]:
       _lowercase:       Optional[int]						=				self.find_component(_UpperCamelCase)
       component_size[u_node] += component_size[v_node]
       self.set_component(_UpperCamelCase)






     def 					UpperCAmelCase__       (				self    :							Dict):
      _lowercase:       Union[str, Any]						=				[]
      _lowercase:       Union[str, Any]						=				0

      _lowercase:       list[Any]						=				[-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)

      _lowercase:       Any						=				self.m_num_of_nodes

      while num_of_components > 1:
       for edge in self.m_edges:
        _lowercase:       Optional[Any]						=				edge

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

       for edge in minimum_weight_edge:
        if isinstance(_UpperCamelCase			,				_UpperCamelCase):
         _lowercase:       Union[str, Any]						=				edge

         _lowercase:       Tuple						=				self.m_component[u]
         _lowercase:       int						=				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

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






def 							__lowerCAmelCase      (			):
 pass








if __name__ == "__main__":
       import doctest

       doctest.testmod()









"""simple docstring"""


from abc import ABC, abstractmethod
from argparse import ArgumentParser




class 						__UpperCamelCase     (     UpperCamelCase						):
					@staticmethod
					@abstractmethod
					def        UpperCAmelCase__ (							UpperCAmelCase							:	ArgumentParser   )	->       Optional[Any]:
											raise NotImplementedError()
					@abstractmethod
					def        UpperCAmelCase__ (							self							:	str   )	->       List[str]:
											raise NotImplementedError()