#include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x s(v), t(v), y(v), m(v); for(int i : range(v)) { scanf("%d", &s[i]); } for(int i : range(v)) { scanf("%d", &t[i]); } for(int i : range(v)) { scanf("%d", &y[i]); } for(int i : range(v)) { scanf("%d", &m[i]); } for(int i : range(v)) { s[i]--; t[i]--; graph[s[i]][route[s[i]]] = t[i]; yen [s[i]][route[s[i]]] = y[i]; mIn [s[i]][route[s[i]]] = m[i]; route[s[i]]++; } for(int i : range(n+1)) { for(int j : range(c+1)) { dp[i][j] = i==0? 0 : inf; } } for(int i : range(n)) { for(int k : range(c+1)) { if(dp[i][k] == inf) { continue; } for(int j : range(route[i])) { int kk = k + yen[i][j]; if(kk > c) { continue; } dp[graph[i][j]][kk] = min(dp[graph[i][j]][kk], dp[i][k] + mIn[i][j]); } } } int res = dp[n-1][c]; if(res == inf) { res = -1; } printf("%d\n", res); return 0; }