Slight Modification from part 1 of this question
Intuition\n Describe your first thoughts on how to solve this problem. \nIt says that you have alternating cost for between edges, so maybe keep track of a inde
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt says that you have alternating cost for between edges, so maybe keep track of a index.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis will help to tell you whether this move will cost 1 or 2 based on the index.\n# Complexity\n- Time complexity: Same as part 1\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Same as part 1\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n    pair<int,int> dir[4] = { {0,1}, {1,0}, {0,-1}, {-1, 0} };\n\npublic:\n    int minTimeToReach(vector<vector<int>>& m) {\n        priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>> >q;\n        int n = m.size();\n        int cols = m[0].size();\n        set<pair<int,int>>vis;\n\n        // cost, nodei, nodej, move_idx\n        q.push({0, 0, 0, 0});\n        \n        while(!q.empty()){\n            auto p = q.top();\n            int cost = p[0];\n            int i = p[1];\n            int j = p[2];\n            int move_idx = p[3];\n            q.pop();\n\n            if(i==n-1 && j==cols-1){\n                return cost;\n            }\n\n            for(auto [x,y] : dir){\n                int newj = j+x;\n                int newi = i+y;\n                if(newj >= 0 && newj < cols && newi >= 0 && newi < n && !vis.count({newi, newj})){\n                    // this adder the part here that will tell us what to add, it will be chosen based on the move_idx.\n                    int adder = 2;\n                    if(move_idx % 2 == 0){\n                        adder = 1;\n                    }\n                    q.push({ max(cost+adder, m[newi][newj] + adder), newi, newj, move_idx+1 });\n                    vis.insert({newi, newj});\n                }\n            }\n\n        } \n\n        return -1;\n\n    }\n};\n```
['C++']