#include #include #include using namespace std; constexpr int INF = 1 << 29; struct P { int pos; int cost; int elapse; }; int S[1500]; int T[1500]; int Y[1500]; int M[1500]; int main() { int N, C, V; cin >> N >> C >> V; for (int i = 0; i < V; i++) cin >> S[i]; for (int i = 0; i < V; i++) cin >> T[i]; for (int i = 0; i < V; i++) cin >> Y[i]; for (int i = 0; i < V; i++) cin >> M[i]; vector

G[N + 1]; for (int i = 0; i < V; i++) { G[S[i]].push_back(P{T[i], Y[i], M[i]}); } queue

que; int elapse[N + 1]; for (int &i: elapse) i = INF; que.push(P{1, 0, 0}); elapse[1] = 0; while (!que.empty()) { auto p = que.front(); que.pop(); if (p.pos == N) break; for (auto q: G[p.pos]) { if (C >= p.cost + q.cost) { que.push(P{q.pos, p.cost + q.cost, p.elapse + q.elapse}); elapse[q.pos] = min(elapse[q.pos], p.elapse + q.elapse); } } } cout << (elapse[N] != INF ? elapse[N] : -1) << endl; }