C++ Solution || 95% Beat Time || Shortest path
Intuition\n Describe your first thoughts on how to solve this problem. \nA Slight variation of shortest path.\n\n# Approach\n Describe your approach to solving 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA Slight variation of shortest path.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity: $$O(n*mlog(n*m))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n*m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#define piii pair<int,pair<int,int>>\n\nclass Solution {\npublic:\n    bool check(int i,int j,int n, int m){\n        return i>=0 && j>=0 && i<n && j<m;\n    }\n\n    int minimumTime(vector<vector<int>>& grid) {\n        int n=grid.size(), m=grid[0].size();\n        if(grid[1][0]>1 && grid[0][1]>1) return -1;\n\n        vector<vector<bool>> visited(n,vector<bool>(m,0));\n        priority_queue<piii,vector<piii>,greater<piii>> pq;\n\n        pq.push({0,{0,0}});\n        int row,col,val;\n        int r[4]={-1,1,0,0};\n        int c[4]={0,0,-1,1};\n\n        while(!pq.empty()){\n            val=pq.top().first;\n            row=pq.top().second.first;\n            col=pq.top().second.second;\n            pq.pop();\n\n            if(row==n-1 && col==m-1) break;\n\n            for(int i=0;i<4;i++){\n                int x=row+r[i], y=col+c[i];\n                if(check(x,y,n,m) && !visited[x][y]){\n                    visited[x][y]=1;\n                    if(grid[x][y]<=val) pq.push({val+1,{x,y}});\n                    else{\n                        if((grid[x][y]-val)%2==0) \n                            pq.push({grid[x][y]+1,{x,y}});\n                        else pq.push({grid[x][y],{x,y}});\n                    }\n                }\n            }\n        }\n        return val;\n\n    }\n};\n```
['C++']