






'''simple docstring'''


def 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						return (pointa[0] - pointa[0]) ** 2 + (pointa[1] - pointa[1]) ** 2







def 	__magic_name__( _A						,      _A=0					):
						'''simple docstring'''





						return sorted(_A						,      key=lambda _A					: x[column]					)







def 	__magic_name__( _A						,      _A						,      _A=float("""inf"""					)					):
						'''simple docstring'''





						for i in range(points_counts - 1					):
												for j in range(i + 1						,      _A					):
																		UpperCamelCase__         = euclidean_distance_sqr(points[i]						,      points[j]					)
																		if current_dis < min_dis:
																								UpperCamelCase__         = current_dis
						return min_dis







def 	__magic_name__( _A						,      _A						,      _A=float("""inf"""					)					):
						'''simple docstring'''





						for i in range(min(6						,      points_counts - 1					)						,      _A					):
												for j in range(max(0						,      i - 6					)						,      _A					):
																		UpperCamelCase__         = euclidean_distance_sqr(points[i]						,      points[j]					)
																		if current_dis < min_dis:
																								UpperCamelCase__         = current_dis
						return min_dis







def 	__magic_name__( _A						,      _A						,      _A					):
						'''simple docstring'''





						if points_counts <= 3:
												return dis_between_closest_pair(_A						,      _A					)

						# recursion
						UpperCamelCase__         = points_counts // 2
						UpperCamelCase__         = closest_pair_of_points_sqr(
						    _A						,      points_sorted_on_y[:mid]						,      _A					)
						UpperCamelCase__         = closest_pair_of_points_sqr(
						    _A						,      points_sorted_on_y[mid:]						,      points_counts - mid					)
						UpperCamelCase__         = min(_A						,      _A					)
						UpperCamelCase__         = []
						for point in points_sorted_on_x:
												if abs(point[0] - points_sorted_on_x[mid][0]					) < closest_pair_dis:
																		cross_strip.append(_A					)

						UpperCamelCase__         = dis_between_closest_in_strip(
						    _A						,      len(_A					)						,      _A					)
						return min(_A						,      _A					)







def 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						UpperCamelCase__         = column_based_sort(_A						,      column=0					)
						UpperCamelCase__         = column_based_sort(_A						,      column=1					)
						return (
						    closest_pair_of_points_sqr(
						        _A						,      _A						,      _A					)
						) ** 0.5


if __name__ == "__main__":
					lowerCamelCase_				: Any    	=							[(2, 3), (12, 30), (40, 50), (5, 1), (12, 10), (3, 4)]
					print('''Distance:''', closest_pair_of_points(points, len(points)))








'''simple docstring'''


from __future__ import annotations

from typing import Any
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									UpperCamelCase__         = num_of_nodes
									UpperCamelCase__         = []
									UpperCamelCase__         = {}






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						int ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







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






			def 				A      (   self							:						str ,      lowercase							:						int			)							->    int:

									'''simple docstring'''







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






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







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






			def 				A      (   self							:						Tuple ,      lowercase							:						list[int] ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







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

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







			def 				A      (   self							:						int			)							->    None:

									'''simple docstring'''







									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(lowercase ,      lowercase			):
																											UpperCamelCase__    ,   UpperCamelCase__    ,   UpperCamelCase__         = edge

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

																											if u_component != v_component:
																																	mst_weight += w
																																	self.union(lowercase ,      lowercase ,      lowercase			)
																																	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 	__magic_name__( ):
						'''simple docstring'''







if __name__ == "__main__":
					import doctest

					doctest.testmod()
