Easy DP✌🙏✌
\t#define pi pair\n\n\tclass Solution {\n\t\tint dp[1001][1001];\n\t\tint f(vector g[],int u,int currTime,int&maxTime,vector& passingFees){\n\t\t\tif(currTime >
\t#define pi pair<int,int>\n\n\tclass Solution {\n\t\tint dp[1001][1001];\n\t\tint f(vector<pi> g[],int u,int currTime,int&maxTime,vector<int>& passingFees){\n\t\t\tif(currTime > maxTime) return (1e8);\n\t\t\tif(u == passingFees.size()-1) return passingFees[u];\n\t\t\tif(dp[u][currTime]!=-1) return dp[u][currTime];\n\n\t\t\tint ans = (1e8);\n\t\t\tfor(auto [cost,v]:g[u]){\n\t\t\t\tans = min(ans,f(g,v,currTime + cost,maxTime,passingFees));\n\t\t\t}\n\t\t\treturn dp[u][currTime] = ans + passingFees[u];\n\t\t}\n\tpublic:\n\t\tint minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n\t\t\tint n = passingFees.size();\n\t\t\tvector<pi> g[n];\n\t\t\tfor(auto it:edges){\n\t\t\t\tg[it[0]].push_back({it[2],it[1]});\n\t\t\t\tg[it[1]].push_back({it[2],it[0]});\n\t\t\t}\n\t\t\tmemset(dp,-1,sizeof dp);\n\t\t\tint ans = f(g,0,0,maxTime,passingFees);\n\t\t\treturn (ans>=(1e8)?-1:ans);\n\t\t}\n\t};
[]