#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; #define INF 1000000000 vector S, T, Y, M; int solve(int N, int C){ bool visited[N+1][C+1]; int sec[N+1][C+1]; rep(i,N+1){ rep(j,C+1){ sec[i][j] = INF; visited[i][j] = false; } } sec[1][0] = 0; while(true){ int minpos, mincost, minsec = INF; REP(i,1,N+1){ rep(j,C+1){ if(minsec > sec[i][j] && !visited[i][j]){ minpos = i; mincost = j; minsec = sec[i][j]; } } } if(minsec == INF) break; if(minpos == N) return minsec; visited[minpos][mincost] = true; rep(i,Y.size()){ int s = S[i]; int t = T[i]; int y = Y[i]; int m = M[i]; if(minpos != s) continue; if(mincost + y <= C && sec[t][mincost+y] > minsec + m){ sec[t][mincost+y] = minsec + m; } } } return -1; } int main(){ int N, C, V, tmp; cin >> N >> C >> V; rep(i,V){ cin >> tmp; S.push_back(tmp); } rep(i,V){ cin >> tmp; T.push_back(tmp); } rep(i,V){ cin >> tmp; Y.push_back(tmp); } rep(i,V){ cin >> tmp; M.push_back(tmp); } cout << solve(N, C) << endl; return 0; }