Dijkstra Algo | Easy | C++ | Beats 90% | Graph
\n# Code\ncpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int m = moveTime.size();\n        int n = moveTime
\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int m = moveTime.size();\n        int n = moveTime[0].size();\n        priority_queue<pair<int,vector<int>>, vector<pair<int,vector<int>>>, greater<pair<int,vector<int>>>> pq;\n        vector<vector<int>> check(m,vector<int>(n,INT_MAX));\n        int dx[4] = {-1,0,1,0};\n        int dy[4] = {0,1,0,-1};\n        pq.push({0, {0,0,1}});\n        while(!pq.empty()){\n            auto it = pq.top();\n            pq.pop();\n            int cx = it.second[0];\n            int cy = it.second[1];\n            int cp = it.second[2];\n            if(cx == m-1 && cy == n-1){\n                return it.first;\n            }\n            int cw = it.first;\n            for(int i = 0; i < 4; i++){\n                int nx = cx + dx[i];\n                int ny = cy + dy[i];\n                if(nx >= m || nx < 0 || ny >= n || ny < 0){\n                    continue;\n                }\n                int nw = max(cw, moveTime[nx][ny]) + cp;\n                if(nw < check[nx][ny]){\n                    check[nx][ny] = nw;\n                    if(cp == 1){\n                        pq.push({nw,{nx,ny,2}});\n                    }else{\n                        pq.push({nw,{nx,ny,1}});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['Array', 'Graph', 'Matrix', 'C++']