





from heapq import heappop, heappush

import numpy as np
def        UpperCamelCase__				(		lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     ):





      """simple docstring"""


      _lowerCAmelCase					,							_lowerCAmelCase												=							grid.shape
      _lowerCAmelCase												=							[-1, 1, 0, 0]
      _lowerCAmelCase												=							[0, 0, -1, 1]
      if allow_diagonal:
            dx += [-1, -1, 1, 1]
            dy += [-1, 1, -1, 1]

      _lowerCAmelCase					,							_lowerCAmelCase												=							[(0, source)], set()
      _lowerCAmelCase												=							np.full((rows, cols)							,     np.inf  )
      _lowerCAmelCase												=							0
      _lowerCAmelCase												=							np.empty((rows, cols)							,     dtype=__UpperCamelCase  )
      _lowerCAmelCase												=							None

      while queue:
            ((_lowerCAmelCase)					,							(_lowerCAmelCase))												=							heappop(__UpperCamelCase  )
            if (x, y) in visited:
                  continue
            visited.add((x, y)  )

            if (x, y) == destination:
                  _lowerCAmelCase												=							[]
                  while (x, y) != source:
                        path.append((x, y)  )
                        _lowerCAmelCase					,							_lowerCAmelCase												=							predecessors[x, y]
                  path.append(__UpperCamelCase  )  # add the source manually
                  path.reverse()
                  return matrix[destination], path

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

      return np.inf, []


if __name__ == "__main__":
      import doctest

      doctest.testmod()













'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available


A__    :       int              ={'''tokenization_herbert''': ['''HerbertTokenizer''']}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__    :       Dict              =['''HerbertTokenizerFast''']


if TYPE_CHECKING:
      from .tokenization_herbert import HerbertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_herbert_fast import HerbertTokenizerFast

else:
      import sys

      A__    :       List[Any]              =_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






