





"""simple docstring"""






from __future__ import annotations

from typing import Any




class 				__lowercase			:







					'''simple docstring'''




					def __init__(						self	,			_UpperCAmelCase     ):
									__a :						Any			       =  num_of_nodes
									__a :						Optional[Any]			       =  []
									__a :						Union[str, Any]			       =  {}







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase	,			_UpperCAmelCase	,			_UpperCAmelCase     ):
									self.m_edges.append([u_node, v_node, weight]     )







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase     ):





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







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase     ):





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







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase	,			_UpperCAmelCase	,			_UpperCAmelCase     ):





									if component_size[u_node] <= component_size[v_node]:
													__a :						str			       =  v_node
													component_size[v_node] += component_size[u_node]
													self.set_component(_lowerCamelCase     )

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







					def  _lowerCamelCase		(						self     ):
									__a :						List[Any]			       =  []
									__a :						Optional[Any]			       =  0

									__a :						List[str]			       =  [-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     )

									__a :						List[Any]			       =  self.m_num_of_nodes

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

																	__a :						str			       =  self.m_component[u]
																	__a :						Optional[int]			       =  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
																									):
																													__a :						List[Any]			       =  [u, v, w]

													for edge in minimum_weight_edge:
																	if isinstance(_lowerCamelCase	,			_lowerCamelCase     ):
																					__a       ,						__a       ,						__a :						Optional[Any]			       =  edge

																					__a :						List[Any]			       =  self.m_component[u]
																					__a :						str			       =  self.m_component[v]

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

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






def     __A      (			)		->		Tuple:
				pass


if __name__ == "__main__":
		import doctest

		doctest.testmod()






"""simple docstring"""






# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
A 			=  abspath(join(dirname(dirname(dirname(__file__))), '''src'''))
sys.path.insert(1, git_repo_path)


# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)

def     __A      (			a_						:Tuple)		->		Dict:
				from transformers.testing_utils import pytest_addoption_shared

				pytest_addoption_shared(a_)






def     __A      (			a_						:Any)		->		int:
				from transformers.testing_utils import pytest_terminal_summary_main

				__a :						str			       =  terminalreporter.config.getoption('''--make-reports''')
				if make_reports:
								pytest_terminal_summary_main(a_   ,       id=a_)