Easy C++ Solution | Memoization
\nclass Solution {\npublic:\n    long dp[1001][1001];\n    vector<pair<int,int>> ed[1001];\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>
```\nclass Solution {\npublic:\n    long dp[1001][1001];\n    vector<pair<int,int>> ed[1001];\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n         memset(dp,-1,sizeof(dp));\n         int n = passingFees.size();\n         for(int i=0; i<edges.size(); i++) {\n               ed[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n               ed[edges[i][1]].push_back({edges[i][0],edges[i][2]});\n         }\n         long ans = solve(0,maxTime,passingFees);\n         return ans == INT_MAX ? -1 : ans;\n    }\n    long solve(int src,int time,vector<int> &fees) {\n         if(src == fees.size() - 1) return fees[src];\n         if(dp[src][time]!=-1) return dp[src][time];\n         long  cnt = INT_MAX;\n         for(auto e : ed[src]) {\n              if(time-e.second>=0) {\n                   cnt = min(cnt,fees[src]+solve(e.first,time-e.second,fees));\n              }\n         }\n        return dp[src][time] = cnt;\n    }\n};\n```
['Dynamic Programming', 'C']