#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; 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 (x.cost > c) continue; mint[x.at] = min(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 (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]); } int dp[50][301] = {}; for (int i = 1; i < n; i++) { for (int j = 0; j <= c; j++) { dp[i][j] = INF; } } for (int i = 0; i < n; i++) { for (auto it = graph[i].begin(), e = graph[i].end(); it != e; ++it) { for (int j = it->cost; j <= c; j++) { dp[it->to][j] = min(dp[it->to][j], dp[i][j - it->cost] + it->time); } } } cout << (dp[n - 1][c] == INF ? -1 : dp[n - 1][c]) << endl; return 0; }