#include #include #include using namespace std; typedef struct data{ int money; int time; }data; int N, C, V; int S[1500], T[1500], Y[1500], M[1500]; map > keiro; int loop(int pos, int money, int time, int min_time){ if(money<0){ return -1; } if(pos == N){ return time; } for(int i=1; i<=N; i++){ if(keiro[pos].find(i) != keiro[pos].end()){ int tmp = loop(i, money-keiro[pos][i].money, time+keiro[pos][i].time, min_time); if(tmp == -1) continue; if(min_time == -1){ min_time = tmp; }else{ min_time = min(min_time, tmp); } } } return min_time; } int main(int argc, char const *argv[]) { cin >> N >> C >> V; for (int i = 0; i < V; ++i){ cin >> S[i]; } for (int i = 0; i < V; ++i){ cin >> T[i]; } for (int i = 0; i < V; ++i){ cin >> Y[i]; } for (int i = 0; i < V; ++i){ cin >> M[i]; } for (int i = 0; i < V; ++i){ keiro[S[i]][T[i]].money = Y[i]; keiro[S[i]][T[i]].time = M[i]; } cout << loop(1, C, 0, -1) << endl; return 0; }