#include using namespace std; struct Edge { int to, cost, time; }; struct State { int node, used_cost, total_time; bool operator>(const State &other) const { return total_time > other.total_time; } }; int shortestPath(int n, int c, vector>& graph) { vector> dp(n, vector(c+1, INT_MAX)); // DP table: min time to reach each node with a cost priority_queue, greater> pq; dp[0][0] = 0; pq.push({0, 0, 0}); while (!pq.empty()) { State curr = pq.top(); pq.pop(); if (curr.total_time > dp[curr.node][curr.used_cost]) continue; for (auto [to, cost, time] : graph[curr.node]) { int new_cost = curr.used_cost + cost; int new_time = curr.total_time + time; if (new_cost <= c && new_time < dp[to][new_cost]) { dp[to][new_cost] = new_time; pq.push({to, new_cost, new_time}); } } } int ans = INT_MAX; for (int i = 0; i <= c; i++) ans = min(ans, dp[n-1][i]); return (ans == INT_MAX ? -1 : ans); } int main() { int n, c, v; cin >> n >> c >> v; vector> graph(n); 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]; for (int i = 0; i < v; i++) { s[i]--, t[i]--; // Convert to zero-based indexing graph[s[i]].push_back({t[i], y[i], m[i]}); } cout << shortestPath(n, c, graph) << endl; return 0; }