#include #include #include #define INF 1e9 #define MAXN 55 #define MAXC 305 int min(int a, int b) { return a < b ? a : b; } int main() { int N, C, V; scanf("%d", &N); scanf("%d", &C); scanf("%d", &V); int *S = (int*)malloc(V * sizeof(int)); int *T = (int*)malloc(V * sizeof(int)); int *Y = (int*)malloc(V * sizeof(int)); int *M = (int*)malloc(V * sizeof(int)); for (int i = 0; i < V; i++) scanf("%d", &S[i]); for (int i = 0; i < V; i++) scanf("%d", &T[i]); for (int i = 0; i < V; i++) scanf("%d", &Y[i]); for (int i = 0; i < V; i++) scanf("%d", &M[i]); int dp[MAXN][MAXC]; for (int i = 1; i <= N; i++) { for (int c = 0; c <= C; c++) { dp[i][c] = INF; } } dp[1][0] = 0; for (int u = 1; u <= N; u++) { for (int c = 0; c <= C; c++) { if (dp[u][c] == INF) continue; for (int i = 0; i < V; i++) { if (S[i] != u) continue; int v = T[i]; int y = Y[i]; int m = M[i]; int newc = c + y; if (newc <= C) { dp[v][newc] = min(dp[v][newc], dp[u][c] + m); } } } } int ans = INF; for (int c = 0; c <= C; c++) { ans = min(ans, dp[N][c]); } if (ans == INF) printf("-1\n"); else printf("%d\n", ans); free(S); free(T); free(Y); free(M); return 0; }