[Python3] Dijkstra's algo
\n\nclass Solution:\n    def minimumTime(self, grid: List[List[int]]) -> int:\n        if grid[0][1] <= 1 or grid[1][0] <= 1: \n            m, n = len(grid), le
\n```\nclass Solution:\n    def minimumTime(self, grid: List[List[int]]) -> int:\n        if grid[0][1] <= 1 or grid[1][0] <= 1: \n            m, n = len(grid), len(grid[0])\n            pq = [(0, 0, 0)]\n            dist = defaultdict(lambda : inf, {(0, 0) : 0})\n            while pq: \n                x, i, j = heappop(pq)\n                if (i, j) == (m-1, n-1): return x \n                for ii, jj in (i-1, j), (i, j-1), (i, j+1), (i+1, j): \n                    if 0 <= ii < m and 0 <= jj < n: \n                        xx = x + 1 + max(0, (grid[ii][jj] - x)//2*2) \n                        if dist[ii, jj] > xx: \n                            heappush(pq, (xx, ii, jj))\n                            dist[ii, jj] = xx \n        return -1 \n```
['Python3']