


'''simple docstring'''
from __future__ import annotations

from typing import Any




class 			lowerCamelCase_   :






      def __init__(					self				:    Optional[Any]						,						_A				:    int ):


          '''simple docstring'''


          UpperCAmelCase__			:		Tuple													=				num_of_nodes
          UpperCAmelCase__			:		list[list[int]]													=				[]
          UpperCAmelCase__			:		dict[int, int]													=				{}






      def lowercase_							(					self				:    int						,						_A				:    int						,						_A				:    int						,						_A				:    int ):


          '''simple docstring'''


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






      def lowercase_							(					self				:    str						,						_A				:    int ):


          '''simple docstring'''


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






      def lowercase_							(					self				:    int						,						_A				:    int ):


          '''simple docstring'''


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






      def lowercase_							(					self				:    Tuple						,						_A				:    list[int]						,						_A				:    int						,						_A				:    int ):


          '''simple docstring'''


          if component_size[u_node] <= component_size[v_node]:
              UpperCAmelCase__			:		Any													=				v_node
              component_size[v_node] += component_size[u_node]
              self.set_component(_A )

          elif component_size[u_node] >= component_size[v_node]:
              UpperCAmelCase__			:		int													=				self.find_component(_A )
              component_size[u_node] += component_size[v_node]
              self.set_component(_A )






      def lowercase_							(					self				:    Tuple ):


          '''simple docstring'''


          UpperCAmelCase__			:		Any													=				[]
          UpperCAmelCase__			:		Any													=				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__			:		Tuple													=				self.m_num_of_nodes

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

                  UpperCAmelCase__			:		Any													=				self.m_component[u]
                  UpperCAmelCase__			:		Optional[int]													=				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(_A						,						_A ):
                      UpperCAmelCase__						,						UpperCAmelCase__						,						UpperCAmelCase__			:		Union[str, Any]													=				edge

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

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

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





def 					a__       (					)    ->	None:
    pass


if __name__ == "__main__":
  import doctest

  doctest.testmod()




'''simple docstring'''
def 					a__       (					lowerCAmelCase__						)    ->	int:
    if a < 0:
        raise ValueError('''Input value must be a positive integer'''						)
    elif isinstance(lowerCAmelCase__  ,					lowerCAmelCase__						):
        raise TypeError('''Input value must be a \'int\' type'''						)
    return bin(lowerCAmelCase__						).count('''1'''						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
