C++ | Recursive Solution with proper comments |New technique of using unordered_map to optimize cost
\n/**\n * @author      : archit \n * @GitHub      : archit-1997\n * @email       : architsingh456@gmail.com\n * @file        : minCostToReachDestinationInTime.c
```\n/**\n * @author      : archit \n * @GitHub      : archit-1997\n * @email       : architsingh456@gmail.com\n * @file        : minCostToReachDestinationInTime.cpp\n * @created     : Friday Jul 23, 2021 13:17:57 IST\n */\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define P pair<int,pair<int,int>>\n\nclass Solution {\npublic:\n\nvector<vector<pair<int,int>>> constructGraph(vector<vector<int>>& edges,int n){\n    vector<vector<pair<int,int>>> graph(n);\n    for(auto e : edges){\n        graph[e[0]].push_back({e[1],e[2]});\n        graph[e[1]].push_back({e[0],e[2]});\n    }\n    return graph;\n}\n\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        int n=passingFees.size();\n        vector<vector<pair<int,int>>> graph=constructGraph(edges,n);\n\n        priority_queue<P,vector<P>,greater<P>> q;\n\n        //{passingFees,{nextNode,time}}\n        q.push({passingFees[0],{0,0}});\n\n        unordered_map<int,int> vis;\n\n        int ans=0;\n        while(!q.empty()){\n            pair<int,pair<int,int>> t=q.top();\n            q.pop();\n\n            int cost=t.first;\n            int curNode=t.second.first,curTime=t.second.second;\n\n            //reached the last node ?\n            if(curNode==(n-1))\n                return cost;\n\n            //mark visited with current time\n            vis[curNode]=curTime;\n\n            for(int i=0;i<graph[curNode].size();i++){\n                int nextNode=graph[curNode][i].first;\n                int nextTime=graph[curNode][i].second;\n\n                int time=curTime+nextTime;\n\n                //if curnode already visited and also with a smaller time\n                if(vis.find(nextNode)!=vis.end() && vis[nextNode]<=time)\n                    continue;\n\n                //we need to mark this node as visited\n                vis[nextNode]=time;\n\n                //push in queue only if time <= totalTime\n                if(time<=maxTime)\n                    q.push({passingFees[nextNode]+cost,{nextNode,time}});\n            }\n\n        }\n        return -1;\n    }\n};\n\n\n```
[]