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

from typing import Any






class    UpperCAmelCase_				:





 def __init__(    self ,       lowercase_):
     snake_case_ :    Tuple     			=						num_of_nodes
     snake_case_ :    list[list[int]]     			=						[]
     snake_case_ :    dict[int, int]     			=						{}





 def        snake_case__		(    self ,       lowercase_ ,       lowercase_ ,       lowercase_):
     self.m_edges.append([u_node, v_node, weight])





 def        snake_case__		(    self ,       lowercase_):

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





 def        snake_case__		(    self ,       lowercase_):

     if self.m_component[u_node] != u_node:
         for k in self.m_component:
             snake_case_ :    str     			=						self.find_component(lowercase_)





 def        snake_case__		(    self ,       lowercase_ ,       lowercase_ ,       lowercase_):

     if component_size[u_node] <= component_size[v_node]:
         snake_case_ :    Optional[int]     			=						v_node
         component_size[v_node] += component_size[u_node]
         self.set_component(lowercase_)

     elif component_size[u_node] >= component_size[v_node]:
         snake_case_ :    Optional[Any]     			=						self.find_component(lowercase_)
         component_size[u_node] += component_size[v_node]
         self.set_component(lowercase_)





 def        snake_case__		(    self):
     snake_case_ :    Optional[int]     			=						[]
     snake_case_ :    Any     			=						0

     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)

     snake_case_ :    int     			=						self.m_num_of_nodes

     while num_of_components > 1:
         for edge in self.m_edges:
             snake_case_ :    Optional[int]     			=						edge

             snake_case_ :    Tuple     			=						self.m_component[u]
             snake_case_ :    Dict     			=						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_ :    str     			=						[u, v, w]

         for edge in minimum_weight_edge:
             if isinstance(lowercase_ ,       lowercase_):
                 snake_case_ :    Optional[Any]     			=						edge

                 snake_case_ :    str     			=						self.m_component[u]
                 snake_case_ :    Optional[Any]     			=						self.m_component[v]

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

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


def 						UpperCamelCase_     (	):
    """simple docstring"""














if __name__ == "__main__":
  import doctest

  doctest.testmod()






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

import math

def 						UpperCamelCase_     (	__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ):
    """simple docstring"""






    if depth < 0:
        raise ValueError("Depth cannot be less than 0"       )

    if len(__SCREAMING_SNAKE_CASE       ) == 0:
        raise ValueError("Scores cannot be empty"       )

    if depth == height:
        return scores[node_index]

    if is_max:
        return max(
            minimax(depth + 1,		node_index * 2,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ),		minimax(depth + 1,		node_index * 2 + 1,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ),		)

    return min(
        minimax(depth + 1,		node_index * 2,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ),		minimax(depth + 1,		node_index * 2 + 1,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       ),		)

def 						UpperCamelCase_     (	):
    """simple docstring"""






    snake_case_ :    int     			=						[9_0, 2_3, 6, 3_3, 2_1, 6_5, 1_2_3, 3_4_4_2_3]
    snake_case_ :    Union[str, Any]     			=						math.log(len(__SCREAMING_SNAKE_CASE       ),		2       )
    print("Optimal value : ",		end=""       )
    print(minimax(0,		0,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       )       )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()




