[Python3] Dijkstra's algo
\n\nclass Solution:\n    def minimumMoves(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        dist = {(0, 0, 0, 1): 0}\n        pq = [(0, 0, 0,
\n```\nclass Solution:\n    def minimumMoves(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        dist = {(0, 0, 0, 1): 0}\n        pq = [(0, 0, 0, 0, 1)]\n        while pq: \n            x, i, j, ii, jj = heappop(pq)\n            if i == n-1 and j == n-2 and ii == n-1 and jj == n-1: return x\n            if ii+1 < n and grid[i+1][j] == grid[ii+1][jj] == 0 and x+1 < dist.get((i+1, j, ii+1, jj), inf): \n                heappush(pq, (x+1, i+1, j, ii+1, jj))\n                dist[i+1, j, ii+1, jj] = x + 1\n            if jj+1 < n and grid[i][j+1] == grid[ii][jj+1] == 0 and x+1 < dist.get((i, j+1, ii, jj+1), inf): \n                heappush(pq, (x+1, i, j+1, ii, jj+1))\n                dist[i, j+1, ii, jj+1] = x + 1\n            if i == ii and ii+1 < n and grid[i+1][j] == grid[i+1][jj] == 0 and x+1 < dist.get((i, j, i+1, j), inf): \n                heappush(pq, (x+1, i, j, i+1, j))\n                dist[i, j, i+1, j] = x + 1\n            if j == jj and jj+1 < n and grid[i][j+1] == grid[ii][j+1] == 0 and x+1 < dist.get((i, j, i, j+1), inf): \n                heappush(pq, (x+1, i, j, i, j+1))\n                dist[i, j, i, j+1] = x + 1\n        return -1 \n```
['Python3']