
from __future__ import annotations

from typing import Any





class 	_lowerCAmelCase					:




				def __init__(					self				,				_UpperCamelCase     )				->      None:
							lowerCAmelCase_						=	num_of_nodes
							lowerCAmelCase_						=	[]
							lowerCAmelCase_						=	{}




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      None:
							self.m_edges.append([u_node, v_node, weight]     )




				def      __a						(					self				,				_UpperCamelCase     )				->      int:

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




				def      __a						(					self				,				_UpperCamelCase     )				->      None:

							if self.m_component[u_node] != u_node:
										for k in self.m_component:
													lowerCAmelCase_						=	self.find_component(_SCREAMING_SNAKE_CASE     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      None:

							if component_size[u_node] <= component_size[v_node]:
										lowerCAmelCase_						=	v_node
										component_size[v_node] += component_size[u_node]
										self.set_component(_SCREAMING_SNAKE_CASE     )

							elif component_size[u_node] >= component_size[v_node]:
										lowerCAmelCase_						=	self.find_component(_SCREAMING_SNAKE_CASE     )
										component_size[u_node] += component_size[v_node]
										self.set_component(_SCREAMING_SNAKE_CASE     )




				def      __a						(					self     )				->      None:
							lowerCAmelCase_						=	[]
							lowerCAmelCase_						=	0

							lowerCAmelCase_						=	[-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     )

							lowerCAmelCase_						=	self.m_num_of_nodes

							while num_of_components > 1:
										for edge in self.m_edges:
													lowerCAmelCase_						=	edge

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

										for edge in minimum_weight_edge:
													if isinstance(_SCREAMING_SNAKE_CASE				,				_SCREAMING_SNAKE_CASE     ):
																lowerCAmelCase_						=	edge

																lowerCAmelCase_						=	self.m_component[u]
																lowerCAmelCase_						=	self.m_component[v]

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

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






def    lowerCamelCase__				(				):




			"""simple docstring"""


			pass


if __name__ == "__main__":
			import doctest

			doctest.testmod()








"""simple docstring"""






from ..utils import DummyObject, requires_backends



class 			A__   (  metaclass=__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	['torch', 'torchsde']

	def __init__(     self:		int       ,			*_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			**_SCREAMING_SNAKE_CASE:		str)				->       Dict:

				"""simple docstring"""

				requires_backends(self       ,			["torch", "torchsde"])

	@classmethod
	def 							_SCREAMING_SNAKE_CASE   (     cls:		Optional[Any]       ,			*_SCREAMING_SNAKE_CASE:		Optional[int]       ,			**_SCREAMING_SNAKE_CASE:		Optional[int])				->       Optional[Any]:

				"""simple docstring"""

				requires_backends(cls       ,			["torch", "torchsde"])







	@classmethod
	def 							_SCREAMING_SNAKE_CASE   (     cls:		Dict       ,			*_SCREAMING_SNAKE_CASE:		List[Any]       ,			**_SCREAMING_SNAKE_CASE:		Any)				->       Optional[int]:

				"""simple docstring"""

				requires_backends(cls       ,			["torch", "torchsde"])