Modified Dijkstra - Intuition based
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:        //time,  1or2     //row, col
    typedef pair<int,pair<int,pair<int,int>>> pii;
    int minTimeToReach(vector<vector<int>>& moveTime) {
        int n = moveTime.size();
        int m = moveTime[0].size();
        vector<vector<int>> dist(n,vector<int>(m,INT_MAX));
        int delRow[] = {-1,0,1,0};
        int delCol[] = {0,1,0,-1};
        priority_queue<pii,vector<pii>,greater<pii>> minh;
        minh.push({0,{1,{0,0}}});
        dist[0][0];

        while(!minh.empty()){
            int curr_time = minh.top().first;
            int _1or2 = minh.top().second.first;
            int row = minh.top().second.second.first;
            int col = minh.top().second.second.second;

            minh.pop();
            for(int i=0;i<4;i++){
                int nrow = row + delRow[i];
                int ncol = col + delCol[i];
                if(nrow>=0 && nrow<n && ncol>=0 && ncol<m){
                      int time = moveTime[nrow][ncol];
                      if(curr_time<time) {
                          dist[nrow][ncol] = time + _1or2;
                          int temp = _1or2==1?2:1;
                          minh.push({time+_1or2,{temp,{nrow,ncol}}});

                      } else {
                         if(dist[nrow][ncol]> curr_time + _1or2 ){
                            dist[nrow][ncol] = curr_time + _1or2;
                              int temp = _1or2==1?2:1;
                              minh.push({curr_time+_1or2,{temp,{nrow,ncol}}});
                         }

                      }



                }

            }
           
        }
         return dist[n-1][m-1];

    }
};
```
['C++']