Dijsktra's || C++
Code\ncpp []\nclass Solution \n{\npublic:\n    bool valid(int r, int c, int rows, int cols)\n    {\n        return (r>=0 && r<rows && c>=0 && c<cols);\n    }\n 
# Code\n```cpp []\nclass Solution \n{\npublic:\n    bool valid(int r, int c, int rows, int cols)\n    {\n        return (r>=0 && r<rows && c>=0 && c<cols);\n    }\n    int minTimeToReach(vector<vector<int>>& moveTime) \n    {\n        int rows=moveTime.size(), cols=moveTime[0].size();\n        priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> q;\n        vector<vector<int>> vis(rows+1, vector<int> (cols+1,0));\n        q.push({0,0,0,1});\n        vis[0][0]=1;\n        vector<pair<int,int>> directions={{1,0},{-1,0},{0,1},{0,-1}};\n        while(!q.empty())\n        {\n            auto v=q.top();\n            q.pop();\n            int time=v[0];\n            int r=v[1], c=v[2];\n            int cost=v[3];\n            if(r==rows-1 && c==cols-1) return time;\n            for(auto it: directions)\n            {\n                int dr=r+it.first, dc=c+it.second;\n                if(valid(dr,dc,rows,cols) && !vis[dr][dc]) \n                {\n                    vis[dr][dc]=1;\n                    int newTime=max(moveTime[dr][dc]+cost,time+cost);\n                    q.push({newTime,dr,dc,cost==1?2:1});\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['Graph', 'Heap (Priority Queue)', 'Shortest Path', 'C++']