Dijkstra Alg Easy
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n    vector<vector<int>> vi;\n    vector<vector<int>> dt;\n    int dx[4] = {0,0,1,-1};\n    int dy[4] = {-1,1,0,0};\n    int n,m;\n    bool isvalid(int x,int y){\n        return (x>=0 and y>=0 and x<n and y<m);\n    }\ntypedef pair<int,pair<int,pair<int,int>>> p;\n    int minTimeToReach(vector<vector<int>>& mt) {\n       \n         n = mt.size();\n         m = mt[0].size();\n          \n        //   memset(vi,0,sizeof(vi));\n          dt = mt;\n          vi = mt;\n          for(int i =0;i<n;i++){\n            for(int j =0;j<m;j++)\n                dt[i][j] = 1e9+2500,  vi[i][j] = 0;          \n          }\n\n          priority_queue<p,vector<p>,greater<p>> pq;\n\n          pq.push({0,{2,{0,0}}});\n          dt[0][0] = 0;\n\n          while(!pq.empty()){\n\n            auto a = pq.top();\n\n            pq.pop();\n\n            int dist = a.first;\n            int prev = a.second.first;\n            int x = a.second.second.first;\n            int y = a.second.second.second;\n\n            if(vi[x][y]) continue;\n\n            vi[x][y] = 1;\n\n            for(int i =0 ;i<4;i++){\n                int xx = x + dx[i];\n                int yy = y + dy[i];\n\n                if(isvalid(xx,yy)){\n                    if(dt[xx][yy]> max(dt[x][y],mt[xx][yy])+2 and prev==1){\n                        dt[xx][yy] =  max(dt[x][y],mt[xx][yy])+2 ;\n                        pq.push({dt[xx][yy],{2,{xx,yy}}});\n                    }\n\n                    if(dt[xx][yy]> max(dt[x][y],mt[xx][yy])+1 and prev==2){\n                        dt[xx][yy] =  max(dt[x][y],mt[xx][yy])+1 ;\n                        pq.push({dt[xx][yy],{1,{xx,yy}}});\n                    }\n                }\n            }\n          }\n\n          return dt[n-1][m-1];\n\n    }\n};\n```
['C++']