#include #include #include #include #define REP(i,a,b) for(i=a;i root; }; int N,C,V; int S[1505]; int T[1505]; int Y[1505]; int M[1505]; struct town town[55]; int dp[55][305] = {0}; int main(void) { int i,j,k,l; cin >> N >> C >> V; /* for(i=0;i<20;i++) { printf("town[%d].root.size() = %d\n",i,town[i].root.size()); } */ rep(i,V) { cin >> S[i]; } rep(i,V) { cin >> T[i]; } rep(i,V) { cin >> Y[i]; } rep(i,V) { cin >> M[i]; } rep(i,V) { Root tmp = {S[i],Y[i],M[i]}; town[T[i]].root.push_back(tmp); } rep(i,C+1) { dp[1][i] = INT_MAX; } dp[1][C] = 0; REP(i,2,N+1) { rep(l,C+1) { dp[i][l] = INT_MAX; int n = town[i].root.size(); for(k=0;k 0) { dp[i][l] = min(dp[town[i].root[k].preCity][l] + town[i].root[k].time ,dp[i][ l - town[i].root[k].money ]); } } } } int minMoney = INT_MAX; rep(i,C+1) { if(minMoney > dp[N][i]) minMoney = dp[N][i]; } if(minMoney == INT_MAX) minMoney = -1; printf("%d\n",minMoney); /* rep(i,N) { rep(j,town[i].root.size()) { printf("%d",i); printf(" %d",town[i].root[j].nextCity); printf(" %d",town[i].root[j].money); printf(" %d\n",town[i].root[j].time); } } */ return 0; }