
from heapq import heappop, heappush

import numpy as np


def      UpperCamelCase   (       __lowerCamelCase	:					np.ndarray							,   __lowerCamelCase	:					tuple[int, int]							,   __lowerCamelCase	:					tuple[int, int]							,   __lowerCamelCase	:					bool							,   ):
       snake_case							,   snake_case			:  int     							= grid.shape
       snake_case			:  Optional[int]     							= [-1, 1, 0, 0]
       snake_case			:  Any     							= [0, 0, -1, 1]
       if allow_diagonal:
              dx += [-1, -1, 1, 1]
              dy += [-1, 1, -1, 1]

       snake_case							,   snake_case			:  str     							= [(0, source)], set()
       snake_case			:  str     							= np.full((rows, cols)							,   np.inf       )
       snake_case			:  Dict     							= 0
       snake_case			:  List[str]     							= np.empty((rows, cols)							,   dtype=__lowerCamelCase       )
       snake_case			:  List[str]     							= None

       while queue:
              ((snake_case)							,   (snake_case))			:  Any     							= heappop(__lowerCamelCase       )
              if (x, y) in visited:
                     continue
              visited.add((x, y)       )

              if (x, y) == destination:
                     snake_case			:  Tuple     							= []
                     while (x, y) != source:
                            path.append((x, y)       )
                            snake_case							,   snake_case			:  List[Any]     							= predecessors[x, y]
                     path.append(__lowerCamelCase       )  # add the source manually
                     path.reverse()
                     return matrix[destination], path

              for i in range(len(__lowerCamelCase       )       ):
                     snake_case							,   snake_case			:  Tuple     							= x + dx[i], y + dy[i]
                     if 0 <= nx < rows and 0 <= ny < cols:
                            snake_case			:  Optional[Any]     							= grid[nx][ny]
                            if next_node == 1 and matrix[nx, ny] > dist + 1:
                                   heappush(__lowerCamelCase							,   (dist + 1, (nx, ny))       )
                                   snake_case			:  Optional[Any]     							= dist + 1
                                   snake_case			:  List[Any]     							= (x, y)

       return np.inf, []


if __name__ == "__main__":
   import doctest

   doctest.testmod()







import qiskit


def      UpperCamelCase   (       __lowerCamelCase	:					int							,   __lowerCamelCase	:					int       ):
       snake_case			:  int     							= qiskit.Aer.get_backend("aer_simulator"       )

       # Create a Quantum Circuit acting on the q register
       snake_case			:  Dict     							= qiskit.QuantumCircuit(__lowerCamelCase							,   __lowerCamelCase       )

       # Apply X (NOT) Gate to Qubits 0 & 1
       circuit.x(0       )
       circuit.x(1       )

       # Map the quantum measurement to the classical bits
       circuit.measure([0, 1]							,   [0, 1]       )

       # Execute the circuit on the qasm simulator
       snake_case			:  Dict     							= qiskit.execute(__lowerCamelCase							,   __lowerCamelCase							,   shots=1000       )

       # Return the histogram data of the results of the experiment.
       return job.result().get_counts(__lowerCamelCase       )


if __name__ == "__main__":
   __lowerCamelCase				=			single_qubit_measure(2, 2)
   print(F'Total count for various states are: {counts}')





