

'''simple docstring'''


from __future__ import annotations

from typing import Any



class 					lowercase						:


							def __init__(			self    ,			_snake_case)							->				int:
								UpperCAmelCase_		:      List[Any]       	=					num_of_nodes
								UpperCAmelCase_		:      list[list[int]]       	=					[]
								UpperCAmelCase_		:      dict[int, int]       	=					{}


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				int:
								self.m_edges.append([u_node, v_node, weight])


							def 						_snake_case							(			self    ,			_snake_case)							->				Union[str, Any]:



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


							def 						_snake_case							(			self    ,			_snake_case)							->				str:



								if self.m_component[u_node] != u_node:
									for k in self.m_component:
										UpperCAmelCase_		:      Tuple       	=					self.find_component(lowerCamelCase_)


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				str:



								if component_size[u_node] <= component_size[v_node]:
									UpperCAmelCase_		:      Dict       	=					v_node
									component_size[v_node] += component_size[u_node]
									self.set_component(lowerCamelCase_)

								elif component_size[u_node] >= component_size[v_node]:
									UpperCAmelCase_		:      Optional[int]       	=					self.find_component(lowerCamelCase_)
									component_size[u_node] += component_size[v_node]
									self.set_component(lowerCamelCase_)





							def 						_snake_case							(			self)							->				List[Any]:
								UpperCAmelCase_		:      int       	=					[]
								UpperCAmelCase_		:      Optional[int]       	=					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[Any]       	=					self.m_num_of_nodes

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

										UpperCAmelCase_		:      Dict       	=					self.m_component[u]
										UpperCAmelCase_		:      Tuple       	=					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_		:      Optional[Any]       	=					[u, v, w]

									for edge in minimum_weight_edge:
										if isinstance(lowerCamelCase_    ,			lowerCamelCase_):
											UpperCAmelCase_		:      str       	=					edge

											UpperCAmelCase_		:      Dict       	=					self.m_component[u]
											UpperCAmelCase_		:      List[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

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







def 						SCREAMING_SNAKE_CASE(  )    ->    Optional[Any]:
	pass





if __name__ == "__main__":
						import doctest

						doctest.testmod()









'''simple docstring'''


from __future__ import annotations

from typing import Any



class 					lowercase						(  a_ ):
							pass



class 					lowercase						:


							def __init__(			self    ,			_snake_case)							->				None:
								UpperCAmelCase_		:      Any       	=					data
								UpperCAmelCase_		:      Node | None       	=					None


							def __iter__(			self)							->				Optional[int]:
								UpperCAmelCase_		:      int       	=					self
								UpperCAmelCase_		:      List[str]       	=					[]
								while node:
									if node in visited:
										raise ContainsLoopError
									visited.append(_snake_case)
									yield node.data
									UpperCAmelCase_		:      Tuple       	=					node.next_node





							@property
							def 						_snake_case							(			self)							->				bool:
								try:
									list(self)
									return False
								except ContainsLoopError:
									return True


if __name__ == "__main__":
						lowerCAmelCase__										= Node(1)
						lowerCAmelCase__										= Node(2)
						lowerCAmelCase__										= Node(3)
						lowerCAmelCase__										= Node(4)
						print(root_node.has_loop)  # False
						lowerCAmelCase__										= root_node.next_node
						print(root_node.has_loop)  # True

						lowerCAmelCase__										= Node(5)
						lowerCAmelCase__										= Node(6)
						lowerCAmelCase__										= Node(5)
						lowerCAmelCase__										= Node(6)
						print(root_node.has_loop)  # False

						lowerCAmelCase__										= Node(1)
						print(root_node.has_loop)  # False






