[C++] || Exact Dijkstra Algo || Priority Queue
\nclass Solution {\npublic:\n    int minimumTime(vector<vector<int>>& grid) \n    {\n        int n = grid.size(), m = grid[0].size();\n        \n        if(grid
```\nclass Solution {\npublic:\n    int minimumTime(vector<vector<int>>& grid) \n    {\n        int n = grid.size(), m = grid[0].size();\n        \n        if(grid[0][1] > grid[0][0] + 1 and grid[1][0] > grid[0][0] + 1)   return -1;\n        \n        priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;\n        vector<vector<bool>>vis(n, vector<bool>(m, false));\n        \n        vis[0][0] = true;\n        pq.push({0, {0, 0}});\n        \n        int dx[] = {-1, 0, 1, 0};\n        int dy[] = {0, 1, 0, -1};\n        \n        while(!pq.empty())\n        {\n            int count = pq.top().first;\n            int row = pq.top().second.first;\n            int col = pq.top().second.second;\n            pq.pop();\n            \n            if (row == n - 1 and col == m - 1)   return count;\n            \n            for (int i=0;i<4;i++)\n            {\n                int newRow = row + dx[i];\n                int newCol = col + dy[i];\n                \n                if (newRow >= 0 and newRow < n and newCol >= 0 and newCol < m)\n                {\n                    if (vis[newRow][newCol])   continue;\n                    \n                    if (grid[newRow][newCol] <= count + 1)  \n                    {\n                        pq.push({count+1, {newRow, newCol}});\n                    }\n                    else\n                    {\n                        int timeTaken = grid[newRow][newCol] - count ;\n                        if (timeTaken % 2 == 0)   timeTaken = grid[newRow][newCol] + 1;\n                        else                      timeTaken = grid[newRow][newCol];\n                        \n                        pq.push({timeTaken, {newRow, newCol}});\n                    }\n                    \n                    vis[newRow][newCol] = true;\n                }\n            }\n        }\n        \n        return -1;\n    }\n};\n```
['C++']