


'''simple docstring'''
from __future__ import annotations

from typing import Any
class    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= num_of_nodes
							UpperCamelCase__   :list[list[int]]												= []
							UpperCamelCase__   :dict[int, int]												= {}




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							self.m_edges.append([u_node, v_node, weight]							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


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




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							if self.m_component[u_node] != u_node:
												for k in self.m_component:
																	UpperCamelCase__   :Dict												= self.find_component(UpperCamelCase_							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


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

							elif component_size[u_node] >= component_size[v_node]:
												UpperCamelCase__   :Union[str, Any]												= self.find_component(UpperCamelCase_							)
												component_size[u_node] += component_size[v_node]
												self.set_component(UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :int												= []
							UpperCamelCase__   :List[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__   :Optional[int]												= self.m_num_of_nodes

							while num_of_components > 1:
												for edge in self.m_edges:
																	UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__   :Tuple												= 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__   :Dict												= [u, v, w]

												for edge in minimum_weight_edge:
																	if isinstance(UpperCamelCase_    ,   UpperCamelCase_							):
																						UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__   :List[Any]												= edge

																						UpperCamelCase__   :Any												= self.m_component[u]
																						UpperCamelCase__   :List[Any]												= self.m_component[v]

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

												UpperCamelCase__   :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'''
from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
		if not (is_transformers_available() and is_torch_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
		from .multicontrolnet import MultiControlNetModel
		from .pipeline_controlnet import StableDiffusionControlNetPipeline
		from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
		from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
		from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline