



'''simple docstring'''





from __future__ import annotations

from typing import Any






class        lowerCAmelCase_:
  '''simple docstring'''




  def __init__(    self  ,__UpperCAmelCase      )    ->		None:
      lowerCAmelCase__ :  List[str]							      =					num_of_nodes
      lowerCAmelCase__ :  list[list[int]]							      =					[]
      lowerCAmelCase__ :  dict[int, int]							      =					{}




  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:
              lowerCAmelCase__ :  Optional[Any]							      =					self.find_component(__UpperCAmelCase      )




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

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

      elif component_size[u_node] >= component_size[v_node]:
          lowerCAmelCase__ :  Union[str, Any]							      =					self.find_component(__UpperCAmelCase      )
          component_size[u_node] += component_size[v_node]
          self.set_component(__UpperCAmelCase      )






  def 							UpperCAmelCase_	(    self      )    ->		None:
      lowerCAmelCase__ :  Union[str, Any]							      =					[]
      lowerCAmelCase__ :  Any							      =					0

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

      lowerCAmelCase__ :  str							      =					self.m_num_of_nodes

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

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

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

                  lowerCAmelCase__ :  Optional[int]							      =					self.m_component[u]
                  lowerCAmelCase__ :  Union[str, Any]							      =					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

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







def    _SCREAMING_SNAKE_CASE  (       ):



    """simple docstring"""







if __name__ == "__main__":
 import doctest

 doctest.testmod()







'''simple docstring'''





from maths.prime_factors import prime_factors
def    _SCREAMING_SNAKE_CASE  (       UpperCamelCase			):



    """simple docstring"""





    if not isinstance(UpperCamelCase							,    UpperCamelCase			):
        lowerCAmelCase__ :  int							      =					f"""Input value of [number={number}] must be an integer"""
        raise TypeError(UpperCamelCase			)
    if number < 1:
        raise ValueError("""Input must be a positive integer"""			)
    return -1 if len(prime_factors(UpperCamelCase			)			) % 2 else 1


if __name__ == "__main__":
 import doctest

 doctest.testmod()


