[C++] Simple to understand  DP solution.
\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        const int INF = 1e9 + 5;\n        int
```\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        const int INF = 1e9 + 5;\n        int n = passingFees.size();\n        vector<vector<pair<int, int>>> adj(n);\n        for(auto e: edges) {\n            int u = e[0];\n            int v = e[1];\n            int w = e[2];\n            adj[u].push_back({v, w});\n            adj[v].push_back({u, w});\n        }\n        vector<vector<int>> dp(maxTime+1, vector<int>(n, INF));\n        //dp[i][j] = min cost to reach city j, int time i\n        dp[0][0] = passingFees[0];\n        for(int t=0; t<=maxTime; ++t) {\n            for(int u=0; u<n; u++) {\n                if(dp[t][u] >= INF)continue;\n                for(auto [v, time]: adj[u]) {\n                    int t2 = t + time;\n                    if(t2 > maxTime)continue;\n                    dp[t2][v] = min(dp[t2][v], dp[t][u] + passingFees[v]);\n                }\n            }\n        }\n        int res = INF;\n        for(int t=0; t<=maxTime; ++t) {\n            res = min(res, dp[t][n-1]);\n        }\n        if(res >= INF)return -1;\n        return res;\n    }\n};\n```
['Dynamic Programming']