


from __future__ import annotations

from typing import Any





class   __a      :
 def __init__(       self    ,			lowerCAmelCase__			) ->    None:




        '''simple docstring'''
        lowercase__:       int        =       num_of_nodes
        lowercase__:       list[list[int]]        =       []
        lowercase__:       dict[int, int]        =       {}
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    None:




        '''simple docstring'''
        self.m_edges.append([u_node, v_node, weight]			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    int:




        '''simple docstring'''

        if self.m_component[u_node] == u_node:
               return u_node
        return self.find_component(self.m_component[u_node]			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    None:




        '''simple docstring'''

        if self.m_component[u_node] != u_node:
               for k in self.m_component:
                      lowercase__:       str        =       self.find_component(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    None:




        '''simple docstring'''

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

        elif component_size[u_node] >= component_size[v_node]:
               lowercase__:       Tuple        =       self.find_component(lowerCAmelCase__			)
               component_size[u_node] += component_size[v_node]
               self.set_component(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    None:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       []
        lowercase__:       Union[str, Any]        =       0

        lowercase__:       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			)

        lowercase__:       Tuple        =       self.m_num_of_nodes

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

                      lowercase__:       int        =       self.m_component[u]
                      lowercase__:       Union[str, Any]        =       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__:       int        =       [u, v, w]

               for edge in minimum_weight_edge:
                      if isinstance(lowerCAmelCase__    ,			lowerCAmelCase__			):
                             lowercase__      ,						lowercase__      ,						lowercase__:       int        =       edge

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

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





def        snake_case_					(  )  ->    None:
       pass


if __name__ == "__main__":
 import doctest

 doctest.testmod()






import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute




def        snake_case_					(  snake_case = 3					)  ->    qiskit.result.counts.Counts:
       if isinstance(snake_case      ,							snake_case					):
              raise TypeError('number of qubits must be a integer.'					)
       if number_of_qubits <= 0:
              raise ValueError('number of qubits must be > 0.'					)
       if math.floor(snake_case					) != number_of_qubits:
              raise ValueError('number of qubits must be exact integer.'					)
       if number_of_qubits > 10:
              raise ValueError('number of qubits too large to simulate(>10).'					)

       lowercase__:       str        =       QuantumRegister(snake_case      ,							'qr'					)
       lowercase__:       str        =       ClassicalRegister(snake_case      ,							'cr'					)

       lowercase__:       List[Any]        =       QuantumCircuit(snake_case      ,							snake_case					)

       lowercase__:       int        =       number_of_qubits

       for i in range(snake_case					):
              quantum_circuit.h(number_of_qubits - i - 1					)
              counter -= 1
              for j in range(snake_case					):
                     quantum_circuit.cp(np.pi / 2 ** (counter - j)      ,							snake_case      ,							snake_case					)

       for k in range(number_of_qubits // 2					):
              quantum_circuit.swap(snake_case      ,							number_of_qubits - k - 1					)

       # measure all the qubits
       quantum_circuit.measure(snake_case      ,							snake_case					)
       # simulate with 10000 shots
       lowercase__:       str        =       Aer.get_backend('qasm_simulator'					)
       lowercase__:       Union[str, Any]        =       execute(snake_case      ,							snake_case      ,							shots=1_00_00					)

       return job.result().get_counts(snake_case					)


if __name__ == "__main__":
 print(
     F'''Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}'''
 )


