'''simple docstring'''





from copy import deepcopy




class 			__A :



    def __init__(self       :       Any  ,     __a       :       Optional[Any] = None  ,     __a       :       int = None					):

         if arr is None and size is not None:
              UpperCAmelCase_			       =  size
              UpperCAmelCase_			       =  [0] * size
         elif arr is not None:
              self.init(_SCREAMING_SNAKE_CASE					)
         else:
              raise ValueError("Either arr or size must be specified"					)



    def    _lowercase		(self       :       Tuple  ,     __a       :       Optional[Any]					):
         UpperCAmelCase_			       =  len(_SCREAMING_SNAKE_CASE					)
         UpperCAmelCase_			       =  deepcopy(_SCREAMING_SNAKE_CASE					)
         for i in range(1  ,     self.size					):
              UpperCAmelCase_			       =  self.next_(_SCREAMING_SNAKE_CASE					)
              if j < self.size:
                   self.tree[j] += self.tree[i]



    def    _lowercase		(self       :       Dict					):
         UpperCAmelCase_			       =  self.tree[:]
         for i in range(self.size - 1  ,     0  ,     -1					):
              UpperCAmelCase_			       =  self.next_(_SCREAMING_SNAKE_CASE					)
              if j < self.size:
                   arr[j] -= arr[i]
         return arr



    @staticmethod
    def    _lowercase		(__a       :       Union[str, Any]					):
         return index + (index & (-index))



    @staticmethod
    def    _lowercase		(__a       :       Any					):
         return index - (index & (-index))



    def    _lowercase		(self       :       Dict  ,     __a       :       str  ,     __a       :       List[Any]					):
         if index == 0:
              self.tree[0] += value
              return
         while index < self.size:
              self.tree[index] += value
              UpperCAmelCase_			       =  self.next_(_SCREAMING_SNAKE_CASE					)



    def    _lowercase		(self       :       Optional[int]  ,     __a       :       Optional[int]  ,     __a       :       str					):
         self.add(_SCREAMING_SNAKE_CASE  ,     value - self.get(_SCREAMING_SNAKE_CASE					)					)



    def    _lowercase		(self       :       Union[str, Any]  ,     __a       :       int					):
         if right == 0:
              return 0
         UpperCAmelCase_			       =  self.tree[0]
         right -= 1  # make right inclusive
         while right > 0:
              result += self.tree[right]
              UpperCAmelCase_			       =  self.prev(_SCREAMING_SNAKE_CASE					)
         return result



    def    _lowercase		(self       :       List[str]  ,     __a       :       Union[str, Any]  ,     __a       :       List[str]					):
         return self.prefix(_SCREAMING_SNAKE_CASE					) - self.prefix(_SCREAMING_SNAKE_CASE					)



    def    _lowercase		(self       :       Any  ,     __a       :       Tuple					):
         return self.query(_SCREAMING_SNAKE_CASE  ,     index + 1					)






    def    _lowercase		(self       :       Tuple  ,     __a       :       Optional[int]					):
         value -= self.tree[0]
         if value < 0:
              return -1

         UpperCAmelCase_			       =  1  # Largest power of 2 <= size
         while j * 2 < self.size:
              j *= 2

         UpperCAmelCase_			       =  0

         while j > 0:
              if i + j < self.size and self.tree[i + j] <= value:
                   value -= self.tree[i + j]
                   i += j
              j //= 2
         return i


if __name__ == "__main__":
    import doctest

    doctest.testmod()










'''simple docstring'''





from __future__ import annotations

from typing import Any

class   _a							:






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






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






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE       )				->     int:

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






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE       )				->     None:

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






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )				->     None:

          if component_size[u_node] <= component_size[v_node]:
               _snake_case				= v_node
               component_size[v_node] += component_size[u_node]
               self.set_component(_SCREAMING_SNAKE_CASE       )

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






     def 							_lowercase      (					self       )				->     None:
          _snake_case				= []
          _snake_case				= 0

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

          _snake_case				= self.m_num_of_nodes

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

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

               for edge in minimum_weight_edge:
                    if isinstance(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       ):
                         _snake_case				,   _snake_case				,   _snake_case				= edge

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

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

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







def       __a      (  )		->					None:

     """simple docstring"""






if __name__ == "__main__":
   import doctest

   doctest.testmod()


