



from heapq import heappop, heappush

import numpy as np
def 		UpperCamelCase     (       snake_case__	:   np.ndarray	,					snake_case__	:   tuple[int, int]	,					snake_case__	:   tuple[int, int]	,					snake_case__	:   bool	,					)     ->					tuple[float | int, list[tuple[int, int]]]:
   UpperCamelCase   :  List[Any]						     =     grid.shape
   UpperCamelCase   :  Tuple						     =     [-1, 1, 0, 0]
   UpperCamelCase   :  List[str]						     =     [0, 0, -1, 1]
   if allow_diagonal:
      dx += [-1, -1, 1, 1]
      dy += [-1, 1, -1, 1]

   UpperCamelCase   :  List[str]						     =     [(0, source)], set()
   UpperCamelCase   :  Optional[Any]						     =     np.full((rows, cols)	,					np.inf     )
   UpperCamelCase   :  Union[str, Any]						     =     0
   UpperCamelCase   :  Optional[Any]						     =     np.empty((rows, cols)	,					dtype=snake_case__     )
   UpperCamelCase   :  List[str]						     =     None

   while queue:
      (UpperCamelCase)   :  Optional[int]						     =     heappop(snake_case__     )
      if (x, y) in visited:
         continue
      visited.add((x, y)     )

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

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

   return np.inf, []


if __name__ == "__main__":
    import doctest

    doctest.testmod()








# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__UpperCAmelCase	       =	abspath(join(dirname(dirname(dirname(__file__))), '''src'''))
sys.path.insert(1, git_repo_path)


# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)
def 		UpperCamelCase     (       snake_case__	:   Dict     )     ->					List[str]:
   from transformers.testing_utils import pytest_addoption_shared

   pytest_addoption_shared(snake_case__     )


def 		UpperCamelCase     (       snake_case__	:   List[Any]     )     ->					Dict:
   from transformers.testing_utils import pytest_terminal_summary_main

   UpperCamelCase   :  Optional[int]						     =     terminalreporter.config.getoption('--make-reports'     )
   if make_reports:
      pytest_terminal_summary_main(snake_case__	,					id=snake_case__     )



