#include #include #include #include #include #include #include #include #include using namespace std; int main(void) { int n, c, v; cin >> n >> c >> v; int s[v], t[v], y[v], m[v]; pair p1, p2; map, pair > mp; vector zero(0); vector > arr(n + 1, zero); vector cost(n + 1, 0); vector time(n + 1, 0); vector pass(n + 1, false); 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]; for (int i = 0; i < v; i++) { mp[make_pair(s[i], t[i])] = make_pair(y[i], m[i]); arr[s[i]].push_back(t[i]); } int x = 1; pass[1] = true; cout << "Nysnpasu" << endl; while (x != n) { for (int i = 0; i < arr[x].size(); i++) { if (cost[x] + mp[make_pair(x, arr[x][i])].first <= c) { cost[arr[x][i]] = cost[x] + mp[make_pair(x, arr[x][i])].first; time[arr[x][i]] = time[x] + mp[make_pair(x, arr[x][i])].second; } } pass[x] = true; x = 0; for (int i = 2; i <= n; i++) if (!pass[i]&&time[i]>0) { x = i; break; } if (x == 0) { cout << -1 << endl; return 0; } for (int i = x; i <= n; i++) { if (!pass[i] && time[x] > time[i] && time[i] > 0) x = i; } } cout << time[n] << endl; return 0; }