




from heapq import heappop, heappush

import numpy as np
def 			SCREAMING_SNAKE_CASE_			(							__A    :			np.ndarray	,					__A    :			tuple[int, int]	,					__A    :			tuple[int, int]	,					__A    :			bool	,					)			->			tuple[float | int, list[tuple[int, int]]]:
   _SCREAMING_SNAKE_CASE	=				grid.shape
   _SCREAMING_SNAKE_CASE	=				[-1, 1, 0, 0]
   _SCREAMING_SNAKE_CASE	=				[0, 0, -1, 1]
   if allow_diagonal:
      dx += [-1, -1, 1, 1]
      dy += [-1, 1, -1, 1]

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

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

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

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

   return np.inf, []


if __name__ == "__main__":
 import doctest

 doctest.testmod()







'''simple docstring'''



import random
def 			SCREAMING_SNAKE_CASE_			(							__A    :			int	,					__A    :			float	,					__A    :			bool = False  )			->			dict:
   _SCREAMING_SNAKE_CASE	=				{i: [] for i in range(__A  )}

   # if probability is greater or equal than 1, then generate a complete graph
   if probability >= 1:
      return complete_graph(__A  )
   # if probability is lower or equal than 0, then return a graph without edges
   if probability <= 0:
      return graph

   # for each couple of nodes, add an edge from u to v
   # if the number randomly generated is greater than probability probability
   for i in range(__A  ):
      for j in range(i + 1	,					__A  ):
         if random.random() < probability:
            graph[i].append(__A  )
            if not directed:
               # if the graph is undirected, add an edge in from j to i, either
               graph[j].append(__A  )
   return graph
def 			SCREAMING_SNAKE_CASE_			(							__A    :			int  )			->			dict:
   return {
       i: [j for j in range(__A  ) if i != j] for i in range(__A  )
   }


if __name__ == "__main__":
 import doctest

 doctest.testmod()

