


from __future__ import annotations

from typing import Any

class 							lowercase  :







     def __init__(						self :						int   ,   _lowercase :						int      ):
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		num_of_nodes
           SCREAMING_SNAKE_CASE__       :  list[list[int]]						     =		[]
           SCREAMING_SNAKE_CASE__       :  dict[int, int]						     =		{}







     def 							lowercase__       (						self :						Union[str, Any]   ,   _lowercase :						int   ,   _lowercase :						int   ,   _lowercase :						int      ):
           self.m_edges.append([u_node, v_node, weight]      )







     def 							lowercase__       (						self :						Optional[int]   ,   _lowercase :						int      ):

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







     def 							lowercase__       (						self :						Optional[Any]   ,   _lowercase :						int      ):

           if self.m_component[u_node] != u_node:
                 for k in self.m_component:
                       SCREAMING_SNAKE_CASE__       :  Any						     =		self.find_component(_lowercase      )







     def 							lowercase__       (						self :						int   ,   _lowercase :						list[int]   ,   _lowercase :						int   ,   _lowercase :						int      ):

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

           elif component_size[u_node] >= component_size[v_node]:
                 SCREAMING_SNAKE_CASE__       :  List[Any]						     =		self.find_component(_lowercase      )
                 component_size[u_node] += component_size[v_node]
                 self.set_component(_lowercase      )







     def 							lowercase__       (						self :						str      ):
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		[]
           SCREAMING_SNAKE_CASE__       :  Any						     =		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__       :  List[str]						     =		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__       :  Union[str, 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__       :  int						     =		[u, v, w]

                 for edge in minimum_weight_edge:
                       if isinstance(_lowercase   ,   _lowercase      ):
                             SCREAMING_SNAKE_CASE__     ,       SCREAMING_SNAKE_CASE__     ,       SCREAMING_SNAKE_CASE__       :  List[str]						     =		edge

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

                 SCREAMING_SNAKE_CASE__       :  List[Any]						     =		[-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()







"""simple docstring"""


import os
from distutils.util import strtobool





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase							)				->   Union[str, Any]:




						'''simple docstring'''



						for e in env_keys:
												lowerCamelCase__   =int(os.environ.get(__lowerCAmelCase  ,       -1							)							)
												if val >= 0:
																		return val
						return default





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase=False							)				->   List[str]:




						'''simple docstring'''



						lowerCamelCase__   =os.environ.get(__lowerCAmelCase  ,       str(__lowerCAmelCase							)							)
						return strtobool(__lowerCAmelCase							) == 1  # As its name indicates `strtobool` actually returns an int...





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase="no"							)				->   Union[str, Any]:




						'''simple docstring'''



						lowerCamelCase__   =os.environ.get(__lowerCAmelCase  ,       str(__lowerCAmelCase							)							)
						return value


