Dijkstra's Algorithm
\nclass Solution:\n    def minTimeToReach(self, moveTime: List[List[int]]) -> int:\n        import heapq\n        m, n = len(moveTime), len(moveTime[0])\n      
```\nclass Solution:\n    def minTimeToReach(self, moveTime: List[List[int]]) -> int:\n        import heapq\n        m, n = len(moveTime), len(moveTime[0])\n        heap = []\n\t\t# state could be 0 (1 sec to reach adjacent cell) or 1 (2 sec to reach adjacent cell)\n        heapq.heappush(heap, (0, 0, 0, 0)) # minTime in which I can reach a node, r, c, state\n        visited = [ [0 for i in range(n)] for j in range(m) ]\n        def isValid(r,c):\n            nonlocal m\n            nonlocal n\n            if 0 <= r < m and 0 <= c < n:\n                return True\n            return False\n        \n        while heap:\n            time, r, c, state = heapq.heappop(heap)\n            extra = 1 if state == 0 else 2\n            if visited[r][c] == 1:\n                continue\n            if r == m-1 and c == n-1:\n                return time\n            visited[r][c] = 1\n            directions = [[1,0],[-1,0],[0,1],[0,-1]]\n            for x,y in directions:\n                nr, nc = x + r, y + c \n                if isValid(nr,nc):\n                    heapq.heappush(heap,(extra + max(time, moveTime[nr][nc]),nr,nc, (state+1) % 2))\n```
['Python']