#include using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i> n >> c >> v; rep(i, v) cin >> s[i]; rep(i, v) cin >> t[i]; rep(i, v) cin >> y[i]; rep(i, v) cin >> m[i]; } struct edge { int to, cost, dist; edge(int to, int cost, int dist) : to(to), cost(cost), dist(dist) {} }; typedef vector > graph; graph G; void construct() { G.assign(n, vector()); rep(i, v) { G[s[i] - 1].emplace_back(t[i] - 1, y[i], m[i]); } } const int N = 50; const int C = 300; const int inf = int(1e9); int dp[N][C + 1]; int solve() { construct(); rep(i, n) rep(j, c + 1) dp[i][j] = inf; dp[0][0] = 0; rep(i, n) rep(j, c + 1) { for (const auto& e : G[i]) { if (j + e.cost > c) continue; dp[e.to][j + e.cost] = min(dp[e.to][j + e.cost], dp[i][j] + e.dist); } } int ans = *min_element(dp[n - 1], dp[n - 1] + c + 1); return ans == inf ? -1 : ans; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); input(); cout << solve() << endl; }