






from heapq import heappop, heappush

import numpy as np



def 					_lowerCamelCase(			lowerCAmelCase__				:		np.ndarray    ,    lowerCAmelCase__				:		tuple[int, int]    ,    lowerCAmelCase__				:		tuple[int, int]    ,    lowerCAmelCase__				:		bool    ,    ):





				'''simple docstring'''







				SCREAMING_SNAKE_CASE_   :	Dict													=   grid.shape
				SCREAMING_SNAKE_CASE_   :	Tuple													=   [-1, 1, 0, 0]
				SCREAMING_SNAKE_CASE_   :	List[str]													=   [0, 0, -1, 1]
				if allow_diagonal:
								dx += [-1, -1, 1, 1]
								dy += [-1, 1, -1, 1]

				SCREAMING_SNAKE_CASE_   :	int													=   [(0, source)], set()
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   np.full((rows, cols)    ,    np.inf      )
				SCREAMING_SNAKE_CASE_   :	Dict													=   0
				SCREAMING_SNAKE_CASE_   :	List[str]													=   np.empty((rows, cols)    ,    dtype=lowerCAmelCase__      )
				SCREAMING_SNAKE_CASE_   :	Tuple													=   None

				while queue:
								(SCREAMING_SNAKE_CASE_)   :	List[str]													=   heappop(lowerCAmelCase__      )
								if (x, y) in visited:
												continue
								visited.add((x, y)      )

								if (x, y) == destination:
												SCREAMING_SNAKE_CASE_   :	Optional[int]													=   []
												while (x, y) != source:
																path.append((x, y)      )
																SCREAMING_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__      )      ):
												SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   x + dx[i], y + dy[i]
												if 0 <= nx < rows and 0 <= ny < cols:
																SCREAMING_SNAKE_CASE_   :	str													=   grid[nx][ny]
																if next_node == 1 and matrix[nx, ny] > dist + 1:
																				heappush(lowerCAmelCase__    ,    (dist + 1, (nx, ny))      )
																				SCREAMING_SNAKE_CASE_   :	List[str]													=   dist + 1
																				SCREAMING_SNAKE_CASE_   :	Dict													=   (x, y)

				return np.inf, []


if __name__ == "__main__":
				import doctest

				doctest.testmod()










import copy
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Union


@dataclass
class 							__a							:





		'''simple docstring'''



		UpperCAmelCase__      :				Optional[Union[str, Path]]				    =						None
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				Optional[Dict]				    =						None
		UpperCAmelCase__      :				Optional[str]				    =						None
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				bool				    =						True
		UpperCAmelCase__      :				Optional[int]				    =						None
		UpperCAmelCase__      :				int				    =						1
		UpperCAmelCase__      :				Optional[Union[str, bool]]				    =						None
		UpperCAmelCase__      :				bool				    =						False
		UpperCAmelCase__      :				Optional[Dict]				    =						None
		UpperCAmelCase__      :				Optional[str]				    =						None


		def   __snake_case			(						self       ):
						return self.__class__(**{k: copy.deepcopy(UpperCamelCase__       ) for k, v in self.__dict__.items()}       )