#include using namespace std; struct Node { int at; int time; int cost; Node(int at, int time, int cost) : at(at), time(time), cost(cost) {} bool operator>(const Node &s) const { if (time != s.time) return time > s.time; if (cost != s.cost) return cost > s.cost; return at > s.at; } }; struct Edge { int to; int time; int cost; Edge(int to, int time, int cost) : to(to), time(time), cost(cost) {} }; typedef vector > AdjList; //隣接リスト typedef vector::iterator Edge_it; const int INF = 100000000; const int NONE = -1; AdjList graph; int c; //sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点 void dijkstra(int s, int t, vector &mint){ priority_queue, greater > pq; pq.push(Node(s, 0, 0)); while(!pq.empty()) { Node x = pq.top(); pq.pop(); if (mint[x.at] != INF || x.cost > c) continue; mint[x.at] = x.time; if (x.at == t) break; for(Edge_it i = graph[x.at].begin(), e = graph[x.at].end(); i != e; ++i) { int tmp_t = x.time + i->time; int tmp_c = x.cost + i->cost; if (mint[i->to] == INF && tmp_c <= c) { pq.push(Node(i->to, tmp_t, tmp_c)); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; int v; cin >> n >> c >> v; vector s(v), t(v), y(v), m(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]; graph = AdjList(n); for (int i = 0; i < v; i++) { s[i]--; t[i]--; graph[s[i]].emplace_back(t[i], m[i], y[i]); } vector mint(n, INF); dijkstra(0, n - 1, mint); cout << (mint[n - 1] == INF ? -1 : mint[n - 1]) << endl; return 0; }