





def 				lowerCAmelCase_ (							A_    ,A_):
    UpperCamelCase__:	int					=     ""
    for word_or_phrase in separated:
        if not isinstance(A_    ,A_):
            raise Exception("join() accepts only strings to be joined")
        joined += word_or_phrase + separator
    return joined.strip(A_)


if __name__ == "__main__":
   from doctest import testmod

   testmod()








from __future__ import annotations

from typing import Any




class        _a    :

      """simple docstring"""


      def __init__(		self:			Optional[int]	,    __lowerCamelCase:			int					):
          '''simple docstring'''


          UpperCamelCase__:	Optional[Any]					=     num_of_nodes
          UpperCamelCase__:	list[list[int]]					=     []
          UpperCamelCase__:	dict[int, int]					=     {}






      def 			UpperCAmelCase_       (		self:			Any	,    __lowerCamelCase:			int	,    __lowerCamelCase:			int	,    __lowerCamelCase:			int					):
          '''simple docstring'''


          self.m_edges.append([u_node, v_node, weight]					)






      def 			UpperCAmelCase_       (		self:			Dict	,    __lowerCamelCase:			int					):
          '''simple docstring'''


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






      def 			UpperCAmelCase_       (		self:			str	,    __lowerCamelCase:			int					):
          '''simple docstring'''


          if self.m_component[u_node] != u_node:
              for k in self.m_component:
                  UpperCamelCase__:	Dict					=     self.find_component(__lowerCamelCase					)






      def 			UpperCAmelCase_       (		self:			str	,    __lowerCamelCase:			list[int]	,    __lowerCamelCase:			int	,    __lowerCamelCase:			int					):
          '''simple docstring'''


          if component_size[u_node] <= component_size[v_node]:
              UpperCamelCase__:	List[str]					=     v_node
              component_size[v_node] += component_size[u_node]
              self.set_component(__lowerCamelCase					)

          elif component_size[u_node] >= component_size[v_node]:
              UpperCamelCase__:	Any					=     self.find_component(__lowerCamelCase					)
              component_size[u_node] += component_size[v_node]
              self.set_component(__lowerCamelCase					)






      def 			UpperCAmelCase_       (		self:			Tuple					):
          '''simple docstring'''


          UpperCamelCase__:	Optional[int]					=     []
          UpperCamelCase__:	Optional[int]					=     0

          UpperCamelCase__:	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					)

          UpperCamelCase__:	Optional[int]					=     self.m_num_of_nodes

          while num_of_components > 1:
              for edge in self.m_edges:
                  UpperCamelCase__				, UpperCamelCase__				, UpperCamelCase__:	List[str]					=     edge

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

              for edge in minimum_weight_edge:
                  if isinstance(__lowerCamelCase	,    __lowerCamelCase					):
                      UpperCamelCase__				, UpperCamelCase__				, UpperCamelCase__:	List[str]					=     edge

                      UpperCamelCase__:	Tuple					=     self.m_component[u]
                      UpperCamelCase__:	Optional[Any]					=     self.m_component[v]

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

              UpperCamelCase__:	List[Any]					=     [-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()

