extended dijkstra
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: O(n * m * log(n * m))\n\n- Space complexity: O(n * m)\n\n# Code\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n    vector<pair<int, int>> edges = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int n = moveTime.size(), m = moveTime[0].size();\n\n        set<vector<ll>> st;\n        ll dist[n][m][2];\n        for(int i = 0; i < n; i++)\n            for(int j = 0; j < m; j++)\n                for(int k = 0; k <= 1; k++)\n                    dist[i][j][k] = LLONG_MAX;\n        \n        vector<ll> temp = {0, 0, 0, 1};\n        st.insert(temp), dist[0][0][1] = 0;\n    \n        while (!st.empty())\n        {\n            auto itr = st.begin();\n            ll dis = (*itr)[0];\n            pair<int, int> node = {(*itr)[1], (*itr)[2]};\n            int currentCost = ((*itr)[3] == 0 ? 1 : 0);\n            st.erase(itr);\n    \n            for (auto it : edges)\n            {\n                ll edgeWeight = -1;\n                pair<int, int> adjNode = {-1, -1};\n\n                if(it.first + node.first < n && it.first + node.first >= 0 && it.second + node.second < m && it.second + node.second >= 0)\n                    adjNode = {it.first + node.first, it.second + node.second}, edgeWeight = moveTime[it.first + node.first][it.second + node.second];\n                else\n                    continue;\n                    \n    \n                if (max(dis + currentCost + 1, edgeWeight + currentCost + 1) < dist[adjNode.first][adjNode.second][currentCost])\n                {\n                    if (dist[adjNode.first][adjNode.second][currentCost] != LLONG_MAX) // node is in set\n                        st.erase({dist[adjNode.first][adjNode.second][currentCost], adjNode.first, adjNode.second, currentCost});\n    \n                    dist[adjNode.first][adjNode.second][currentCost] = max(dis + currentCost + 1, edgeWeight + currentCost + 1);\n                    st.insert({dist[adjNode.first][adjNode.second][currentCost], adjNode.first, adjNode.second, currentCost});\n                }\n            }\n        }\n\n        return min(dist[n - 1][m - 1][0], dist[n - 1][m - 1][1]);\n    }\n};\n```
['C++']