#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #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 minTime = INT_MAX; void min_money(int currentTown,int balance,int totalTime) { int i,j,k,l; int n = town[currentTown].root.size(); if(N == currentTown) { if(minTime > totalTime) minTime = totalTime; return; } for(i=0;i town[currentTown].root[i].money) { min_money(town[currentTown].root[i].nextCity ,balance-town[currentTown].root[i].money ,totalTime + town[currentTown].root[i].time); } } } 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 = {T[i],Y[i],M[i]}; town[S[i]].root.push_back(tmp); } min_money(1,C,0); if(minTime == INT_MAX) minTime = -1; printf("%d\n",minTime); /* 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; }