#include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long long int lli; lli MOD = 1000000007; lli n, c, v; struct edge { lli s, t, y, m; }; struct node { lli cur, d, time; }; vector e[1555]; bool ok(lli time) { lli dis[100] = {}; rep(i, 100) dis[i] = -1; auto comp = [](const node l, const node r) { return l.d < r.d; }; priority_queue, decltype(comp)> que(comp); que.push(node{0, 0, 0}); int cnt = 0; while (!que.empty()) { cnt++; lli d = que.top().d; lli cur = que.top().cur; lli t = que.top().time; //cout << cur << endl; que.pop(); if (cnt > 1e5) break; if (time < t) continue; if (dis[cur] != -1) dis[cur] = min(d, dis[cur]); else dis[cur] = d; rep(i, e[cur].size()) { int nx = e[cur][i].t; //if ((dis[nx] >= 0 && dis[nx] < e[cur][i].y + d) || t + e[cur][i].m > time) // continue; if (t + e[cur][i].m > time) continue; que.push(node{ nx, e[cur][i].y + d, t + e[cur][i].m}); if (dis[nx] == -1) dis[nx] = e[cur][i].y + d; else dis[nx] = min(e[cur][i].y + d, dis[nx]); } } if (dis[n - 1] == -1) return false; return dis[n - 1] <= c; } int main() { cin >> n >> c >> v; lli s[2000], t[2000], y[2000], m[2000]; rep(i, v) cin >> s[i]; rep(i, v) cin >> t[i]; rep(i, v) cin >> y[i]; rep(i, v) cin >> m[i]; rep(i, v) { s[i]--, t[i]--; e[s[i]].push_back(edge{s[i], t[i], y[i], m[i]}); e[t[i]].push_back(edge{t[i], s[i], y[i], m[i]}); } lli up = 100000; lli low = 0; if (!ok(up)) { cout << -1 << endl; return 0; } while (up - low > 1) { lli mid = (up + low) / 2; if (ok(mid)) up = mid; else low = mid; } cout << up << endl; }