C++ ||DP
\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        int n=passingFees.size();\n        ve
```\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        int n=passingFees.size();\n        vector<vector<pair<int,int>>>vec(n);\n        for(auto it:edges){\n            vec[it[0]].emplace_back(it[1],it[2]);\n            vec[it[1]].emplace_back(it[0],it[2]);\n        }\n        const int inf=(int)1e9+5;\n        vector<vector<int>>dp(maxTime+1,vector<int>(n,inf));\n        dp[0][0]=passingFees[0];\n        for(int time=0;time<maxTime;time++){\n            for(int node=0;node<n;node++){\n                if(dp[time][node]>=inf){\n                    continue;\n                }\n                for(auto[x,y]:vec[node]){\n                    if(y+time<=maxTime){\n                        dp[y+time][x]=min(dp[y+time][x],dp[time][node]+passingFees[x]);\n                    }\n                }\n            }\n        }\n        int ans=inf;\n        for(int i=0;i<=maxTime;i++){\n            ans=min(ans,dp[i][n-1]);\n        }\n        return ans>=inf?-1:ans;\n    }\n};\n```
[]