#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 int Y[55][55]; int M[55][55]; 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(minpos == N) return minsec; if(minsec == INF) break; visited[minpos][mincost] = true; REP(i,1,N+1){ if(mincost + Y[minpos][i] <= C && sec[i][mincost+Y[minpos][i]] > sec[minpos][mincost] + M[minpos][i]){ sec[i][mincost+Y[minpos][i]] = sec[minpos][mincost] + M[minpos][i]; } } } return -1; } int main(){ int N, C, V, tmp; rep(i,55) rep(j,55){ Y[i][j] = INF; M[i][j] = INF; } cin >> N >> C >> V; vector S, T; rep(i,V){ cin >> tmp; S.push_back(tmp); } rep(i,V){ cin >> tmp; T.push_back(tmp); } rep(i,V){ cin >> tmp; Y[S[i]][T[i]] = tmp; } rep(i,V){ cin >> tmp; M[S[i]][T[i]] = tmp; } cout << solve(N, C) << endl; return 0; }