EASY C++ Solution Beats 100% of the user || find-minimum-time-to-reach-last-room-ii
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& mv) {\n        int m = mv.size();\n        int n = mv[0].size(); \n  
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& mv) {\n        int m = mv.size();\n        int n = mv[0].size(); \n        priority_queue<pair<pair<int,int>,pair<int,int>>,vector<pair<pair<int,int>,pair<int,int>>>,greater<pair<pair<int,int>,pair<int,int>>>>pq;//{{t,len},{x,y}};\n        vector<vector<int>>res(m,vector<int>(n,INT_MAX));\n        res[0][0]=0;\n        pq.push({{0,2},{0,0}});//2 signify that next coloum will get 1 in addition in time\n        int delr[]={-1,0,+1,0};\n        int delc[]={0,-1,0,+1};\n        while(!pq.empty()){\n            int t = pq.top().first.first;\n            int len = pq.top().first.second;\n            int x = pq.top().second.first;\n            int y = pq.top().second.second;\n            if(x==m-1&&y==n-1){\n                return t;\n            }\n            pq.pop();\n            for(int i=0;i<4;i++){\n                int nrow = x + delr[i];\n                int ncol = y + delc[i];\n                if(nrow>=0&&nrow<m&&ncol>=0&&ncol<n){\n                    int newdist ;\n                    if(len == 2){\n                        newdist = max(t+1,mv[nrow][ncol]+1);\n                        if(newdist< res[nrow][ncol]){\n                            res[nrow][ncol]=newdist;\n                            pq.push({{newdist,1},{nrow,ncol}});\n                        } \n                    }else{\n                        newdist = max(t+2,mv[nrow][ncol]+2);\n                        if(newdist<res[nrow][ncol]){\n                            res[nrow][ncol]=newdist;\n                            pq.push({{newdist,2},{nrow,ncol}});\n                        }\n                    }\n                }\n            }\n\n        }\n        return -1;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'C++']