#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i,n) for (int i = 0; i < (n); ++i) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n >> c >> v; vector>>> e(n); vector s(v),t(v),y(v),m(v); 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){ s[i]--,t[i]--; e[s[i]].push_back({t[i],{y[i],m[i]}}); } priority_queue>,vector>>,greater>>> pq; vector> d(n,vector(c+1,INF)); d[0][c]=0; pq.push({0,{0,c}}); while(!pq.empty()){ auto p=pq.top(); pq.pop(); ll u=p.first,v=p.second.first,w=p.second.second; if(u>d[v][w]){ continue; } for(auto x:e[v]){ ll i=x.first,j=x.second.first,k=x.second.second; if(w-j>=0){ if(chmin(d[i][w-j],d[v][w]+k)){ pq.push({d[i][w-j],{i,w-j}}); } } } } ll ans=INF; for(int i=0;i<=c;i++){ chmin(ans,d[n-1][i]); } cout << (ans==INF?-1:ans) << endl; }