"""simple docstring"""

from __future__ import annotations

from typing import Any







class      UpperCAmelCase_       :






							def __init__(		self :      Tuple     ,						__UpperCamelCase :      Tuple  )       ->       Any:
												_UpperCamelCase      						=	num_of_nodes
												_UpperCamelCase      						=	[]
												_UpperCamelCase      						=	{}






							def       _UpperCamelCase			(		self :      Optional[int]     ,						__UpperCamelCase :      Dict     ,						__UpperCamelCase :      int     ,						__UpperCamelCase :      List[str]  )       ->       Tuple:
												self.m_edges.append([u_node, v_node, weight]  )






							def       _UpperCamelCase			(		self :      Optional[int]     ,						__UpperCamelCase :      List[Any]  )       ->       int:

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






							def       _UpperCamelCase			(		self :      List[str]     ,						__UpperCamelCase :      Any  )       ->       List[str]:

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






							def       _UpperCamelCase			(		self :      Union[str, Any]     ,						__UpperCamelCase :      Optional[int]     ,						__UpperCamelCase :      int     ,						__UpperCamelCase :      int  )       ->       Union[str, Any]:

												if component_size[u_node] <= component_size[v_node]:
																	_UpperCamelCase      						=	v_node
																	component_size[v_node] += component_size[u_node]
																	self.set_component(__lowerCamelCase  )

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






							def       _UpperCamelCase			(		self :      int  )       ->       Dict:
												_UpperCamelCase      						=	[]
												_UpperCamelCase      						=	0

												_UpperCamelCase      						=	[-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      						=	self.m_num_of_nodes

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

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

																	for edge in minimum_weight_edge:
																						if isinstance(__lowerCamelCase     ,						__lowerCamelCase  ):
																											_UpperCamelCase						,							_UpperCamelCase						,							_UpperCamelCase      						=	edge

																											_UpperCamelCase      						=	self.m_component[u]
																											_UpperCamelCase      						=	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      						=	[-1] * self.m_num_of_nodes
												print(F'''The total weight of the minimal spanning tree is: {mst_weight}'''  )






def      lowercase		(						)						->   None:
					pass


if __name__ == "__main__":
		import doctest

		doctest.testmod()







from ..utils import DummyObject, requires_backends




class     SCREAMING_SNAKE_CASE__ (						metaclass=UpperCamelCase__      ):
 __SCREAMING_SNAKE_CASE							       =	['''keras_nlp''']



 def __init__(							self,*__lowerCamelCase,**__lowerCamelCase ):
        requires_backends(self,['''keras_nlp'''] )





