BFS
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int n = moveTime.size();\n        int m = moveTi
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int n = moveTime.size();\n        int m = moveTime[0].size();\n        priority_queue<tuple<int, int, int, bool>,\n                       vector<tuple<int, int, int, bool>>, greater<>>\n            pq;\n\n        vector<vector<int>> minTime(n, vector<int>(m, INT_MAX));\n        minTime[0][0] = 0;\n        pq.push({0, 0, 0, false});\n\n        vector<pair<int, int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\n        while (!pq.empty()) {\n            auto [currTime, x, y, turn] = pq.top();\n            pq.pop();\n\n            if (x == n - 1 && y == m - 1) {\n                return currTime;\n            }\n\n            int waitTime = (turn == false) ? 1 : 2;\n\n            for (auto [dx, dy] : directions) {\n                int nx = x + dx;\n                int ny = y + dy;\n\n                if (nx >= 0 && nx < n && ny >= 0 && ny < m) {\n                    int newWaitTime =\n                        max(currTime + waitTime, moveTime[nx][ny] + waitTime);\n\n                    if (newWaitTime < minTime[nx][ny]) {\n                        minTime[nx][ny] = newWaitTime;\n                        pq.push({newWaitTime, nx, ny, !turn});\n                    }\n                }\n            }\n        }\n\n        return -1;\n    }\n};\n```
['Heap (Priority Queue)', 'C++']