

from __future__ import annotations

from typing import Any







class        a__       :







  """simple docstring"""




  def __init__(			self    : Any				,				UpperCAmelCase__    : int		)					->None:
        """simple docstring"""







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


  def  _lowercase      (			self    : int				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : int		)					->None:
        """simple docstring"""







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


  def  _lowercase      (			self    : Optional[int]				,				UpperCAmelCase__    : int		)					->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    : str				,				UpperCAmelCase__    : int		)					->None:
        """simple docstring"""







        if self.m_component[u_node] != u_node:
              for k in self.m_component:
                    SCREAMING_SNAKE_CASE :      List[str]       =   self.find_component(UpperCAmelCase__		)


  def  _lowercase      (			self    : int				,				UpperCAmelCase__    : list[int]				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : int		)					->None:
        """simple docstring"""







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

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




  def  _lowercase      (			self    : int		)					->None:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   []
        SCREAMING_SNAKE_CASE :      Dict       =   0

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

        SCREAMING_SNAKE_CASE :      Any       =   self.m_num_of_nodes

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

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

              for edge in minimum_weight_edge:
                    if isinstance(UpperCAmelCase__				,				UpperCAmelCase__		):
                          SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Dict       =   edge

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

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






def 					__lowercase      (     )     ->						None:
      pass


if __name__ == "__main__":
  import doctest

  doctest.testmod()







def 					__lowercase      (     _A						,    _A			)     ->						int:
      return int((input_a, input_a).count(1			) != 0			)






def 					__lowercase      (     )     ->						None:
      assert or_gate(0						,    0			) == 0
      assert or_gate(0						,    1			) == 1
      assert or_gate(1						,    0			) == 1
      assert or_gate(1						,    1			) == 1


if __name__ == "__main__":
  print(or_gate(0, 1))
  print(or_gate(1, 0))
  print(or_gate(0, 0))
  print(or_gate(1, 1))




