#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0; i #define VLL vector #define VVI vector> #define VVLL vector> #define VC vector #define VS vector #define VVC vector> #define VB vector #define VVB vector> #define fore(i,a) for(auto &i:a) typedef pair P; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1 << 30; const ll INFL = 1LL<<60; const ll mod =1000000007; int n, c, v; int ans = INF; vector>> g[1505]; VI tt(1505, INF); VI mm(1505, INF); void dfs(int p, int cost, int time) { if (p == n) { ans = min(ans, time); return; } for (auto i : g[p]) { int co = cost + i.second.first; int ti = time + i.second.second; if (tt[i.first] >= co || mm[i.first] >= ti) { if (c >= co) { if (tt[i.first] > co && mm[i.first] > ti) { tt[i.first] = co; mm[i.first] = ti; } dfs(i.first, co, ti); } } } } int main() { cin >> n >> c >> v; VI 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) { g[s[i]].push_back({ t[i],{y[i],m[i]} }); } dfs(1, 0, 0); if (ans == INF)cout << -1 << endl; else cout << ans << endl; }