


'''simple docstring'''



from __future__ import annotations

from typing import Any


class 		_snake_case					:




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




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




					def 				snake_case__						(      self							,							_lowerCamelCase):

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




					def 				snake_case__						(      self							,							_lowerCamelCase):

								if self.m_component[u_node] != u_node:
											for k in self.m_component:
														UpperCAmelCase__  :					Optional[int]        =     self.find_component(_lowerCamelCase)




					def 				snake_case__						(      self							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase):

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

								elif component_size[u_node] >= component_size[v_node]:
											UpperCAmelCase__  :					str        =     self.find_component(_lowerCamelCase)
											component_size[u_node] += component_size[v_node]
											self.set_component(_lowerCamelCase)




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					List[Any]        =     []
								UpperCAmelCase__  :					Optional[Any]        =     0

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

								UpperCAmelCase__  :					int        =     self.m_num_of_nodes

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

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

											for edge in minimum_weight_edge:
														if isinstance(_lowerCamelCase							,							_lowerCamelCase):
																	UpperCAmelCase__   ,       UpperCAmelCase__   ,       UpperCAmelCase__  :					str        =     edge

																	UpperCAmelCase__  :					Tuple        =     self.m_component[u]
																	UpperCAmelCase__  :					List[Any]        =     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

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







def     _UpperCamelCase      (		):
			pass


if __name__ == "__main__":
		import doctest

		doctest.testmod()



'''simple docstring'''



import warnings
from functools import wraps
from typing import Callable







def     _UpperCamelCase      (		UpperCamelCase__					):

			@wraps(UpperCamelCase__					)
			def _inner_fn(*UpperCamelCase__ ,      **UpperCamelCase__					):
						warnings.warn(
						    (f'''\'{fn.__name__}\' is experimental and might be subject to breaking changes in the future.''') ,      UpperCamelCase__ ,      )
						return fn(*UpperCamelCase__ ,      **UpperCamelCase__					)

			return _inner_fn