#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]; struct ST { int pos; int cost; int sec; }; int solve(int N, int C){ ST st; st.pos = 1; st.cost = 0; st.sec = 0; vector visited(N+1, INF); queue que; que.push(st); while(!que.empty()){ st = que.front(); que.pop(); if(visited[st.pos] < st.sec) continue; visited[st.pos] = st.sec; REP(i,1,N+1){ if(Y[st.pos][i] != INF){ ST nxt; nxt.pos = i; nxt.cost = st.cost + Y[st.pos][i]; nxt.sec = st.sec + M[st.pos][i]; if(nxt.cost > C) continue; que.push(nxt); } } } if(visited[N] == INF) return -1; return visited[N]; } 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; }