

"""simple docstring"""





from __future__ import annotations

from typing import Any




class 					_lowerCAmelCase  :







 """simple docstring"""







 def __init__(			self							:			Any,					UpperCAmelCase__							:			int	):
    __lowercase								=						num_of_nodes
    __lowercase								=						[]
    __lowercase								=						{}


 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			int	):
    self.m_edges.append([u_node, v_node, weight]	)


 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			int	):

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


 def 					_lowercase (			self							:			List[Any],					UpperCAmelCase__							:			int	):

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


 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			list[int],					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			int	):

    if component_size[u_node] <= component_size[v_node]:
       __lowercase								=						v_node
       component_size[v_node] += component_size[u_node]
       self.set_component(UpperCAmelCase__	)

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



 def 					_lowercase (			self							:			Any	):
    __lowercase								=						[]
    __lowercase								=						0

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

    __lowercase								=						self.m_num_of_nodes

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

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

       for edge in minimum_weight_edge:
          if isinstance(UpperCAmelCase__,					UpperCAmelCase__	):
             __lowercase		,__lowercase		,__lowercase								=						edge

             __lowercase								=						self.m_component[u]
             __lowercase								=						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

       __lowercase								=						[-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 __future__ import annotations

from scipy.special import comb  # type: ignore



class 			_UpperCAmelCase :






		'''simple docstring'''

		def __init__(self				,       a_					):





			'''simple docstring'''

			__snake_case	:						List[str]						=				list_of_points
			# Degree determines the flexibility of the curve.
			# Degree = 1 will produce a straight line.
			__snake_case	:						Optional[Any]						=				len(a_					) - 1



		def 				SCREAMING_SNAKE_CASE  (self				,       a_					):





			'''simple docstring'''

			assert 0 <= t <= 1, "Time t must be between 0 and 1."
			__snake_case	:						list[float]						=				[]
			for i in range(len(self.list_of_points					)					):
				# basis function for each i
				output_values.append(
				    comb(self.degree				,       a_					) * ((1 - t) ** (self.degree - i)) * (t**i)					)
			# the basis must sum up to 1 for it to produce a valid Bezier curve.
			assert round(sum(a_					)				,       5					) == 1
			return output_values



		def 				SCREAMING_SNAKE_CASE  (self				,       a_					):





			'''simple docstring'''

			assert 0 <= t <= 1, "Time t must be between 0 and 1."

			__snake_case	:						List[str]						=				self.basis_function(a_					)
			__snake_case	:						str						=				0.0
			__snake_case	:						Union[str, Any]						=				0.0
			for i in range(len(self.list_of_points					)					):
				# For all points, sum up the product of i-th basis function and i-th point.
				x += basis_function[i] * self.list_of_points[i][0]
				y += basis_function[i] * self.list_of_points[i][1]
			return (x, y)



		def 				SCREAMING_SNAKE_CASE  (self				,       a_ = 0.01					):





			'''simple docstring'''

			from matplotlib import pyplot as plt  # type: ignore

			__snake_case	:						list[float]						=				[]  # x coordinates of points to plot
			__snake_case	:						list[float]						=				[]  # y coordinates of points to plot

			__snake_case	:						int						=				0.0
			while t <= 1:
				__snake_case	:						Union[str, Any]						=				self.bezier_curve_function(a_					)
				to_plot_x.append(value[0]					)
				to_plot_y.append(value[1]					)
				t += step_size

			__snake_case	:						List[Any]						=				[i[0] for i in self.list_of_points]
			__snake_case	:						Any						=				[i[1] for i in self.list_of_points]

			plt.plot(
			    a_				,       a_				,       color='''blue'''				,       label='''Curve of Degree ''' + str(self.degree					)				,       )
			plt.scatter(a_				,       a_				,       color='''red'''				,       label='''Control Points'''					)
			plt.legend()
			plt.show()


if __name__ == "__main__":
			import doctest

			doctest.testmod()

			BezierCurve([(1, 2), (3, 5)]).plot_curve()  # degree 1
			BezierCurve([(0, 0), (5, 5), (5, 0)]).plot_curve()  # degree 2
			BezierCurve([(0, 0), (5, 5), (5, 0), (2.5, -2.5)]).plot_curve()  # degree 3





