#include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x S, T, Y, M; vector> routes; vector> dp; int main(void) { scanf("%d%d%d", &N, &C, &V); S.resize(V); T.resize(V); Y.resize(V); M.resize(V); routes.resize(N); 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)) { routes[--S[i]].push_back(Route({--T[i], Y[i], M[i]})); } dp.assign(N, vector(C+1, inf)); dp[0][0] = 0; for(int v : range(N)) { for(int cost : range(C+1)) { for(Route route : routes[v]) { int ncost = cost + route.cost; if(ncost > C) { continue; } dp[route.to][ncost] = min(dp[route.to][ncost], dp[v][cost] + route.time); } } } int res = *min_element(dp[N-1].begin(), dp[N-1].end()); if(res == inf) { res = -1; } printf("%d\n", res); return 0; }