


import math


class   a__	:

       def __init__(   self      :     int      ,							lowerCamelCase_      :     Dict=0    ):  # a graph with Node 0,1,...,N-1
            a_    :     Optional[Any]										=    n
            a_    :     Dict										=    [
                [math.inf for j in range(0      ,							lowerCamelCase_    )] for i in range(0      ,							lowerCamelCase_    )
            ]  # adjacency matrix for weight
            a_    :     List[str]										=    [
                [math.inf for j in range(0      ,							lowerCamelCase_    )] for i in range(0      ,							lowerCamelCase_    )
            ]  # dp[i][j] stores minimum distance from i to j

       def 						UpperCAmelCase(   self      :     Optional[int]      ,							lowerCamelCase_      :     Dict      ,							lowerCamelCase_      :     Optional[Any]      ,							lowerCamelCase_      :     List[str]    ):
            a_    :     Optional[int]										=    w

       def 						UpperCAmelCase(   self      :     Dict    ):
            for k in range(0      ,							self.n    ):
                 for i in range(0      ,							self.n    ):
                      for j in range(0      ,							self.n    ):
                           a_    :     Tuple										=    min(self.dp[i][j]      ,							self.dp[i][k] + self.dp[k][j]    )

       def 						UpperCAmelCase(   self      :     List[str]      ,							lowerCamelCase_      :     List[Any]      ,							lowerCamelCase_      :     List[str]    ):
            return self.dp[u][v]


if __name__ == "__main__":
       __lowerCamelCase        =     Graph(5)
       graph.add_edge(0, 2, 9)
       graph.add_edge(0, 4, 10)
       graph.add_edge(1, 3, 5)
       graph.add_edge(2, 3, 7)
       graph.add_edge(3, 0, 10)
       graph.add_edge(3, 1, 2)
       graph.add_edge(3, 2, 1)
       graph.add_edge(3, 4, 6)
       graph.add_edge(4, 1, 3)
       graph.add_edge(4, 2, 4)
       graph.add_edge(4, 3, 9)
       graph.floyd_warshall()
       graph.show_min(1, 4)
       graph.show_min(0, 3)







from heapq import heappop, heappush

import numpy as np



def  _a			(						__UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase  ,  ):
     a_			,			a_    :     Any										=    grid.shape
     a_    :     Dict										=    [-1, 1, 0, 0]
     a_    :     List[Any]										=    [0, 0, -1, 1]
     if allow_diagonal:
          dx += [-1, -1, 1, 1]
          dy += [-1, 1, -1, 1]

     a_			,			a_    :     int										=    [(0, source)], set()
     a_    :     Optional[Any]										=    np.full((rows, cols)  ,  np.inf )
     a_    :     Tuple										=    0
     a_    :     Optional[Any]										=    np.empty((rows, cols)  ,  dtype=__UpperCamelCase )
     a_    :     Optional[Any]										=    None

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

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

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

     return np.inf, []


if __name__ == "__main__":
       import doctest

       doctest.testmod()



