#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i--) #define FOR(i, m, n) for(ll i = m;i < n;i++) #define FORR(i, m, n) for(ll i = m;i >= n;i--) #define REPO(i, n) for(ll i = 1;i <= n;i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(),n.end() #define MOD 1000000007 #define P pair ll n, c, m, ans = INF; #define PP pair ll d[60][310]; // 結果 struct edge { ll to, cost, coin; }; vector g[110000]; //隣接リスト to, cost void dijkstra(ll a) { //実装汚いからそのうち直す priority_queue, greater > q; // to, cost, 条件 REP(i, n)fill(d[i], d[i] + 310, INF); d[a][0] = 0; q.push(PP(0, P(a, 0))); while (!q.empty()) { PP p = q.top(); q.pop(); ll v = p.second.first; if (d[v][p.second.second] < p.first) continue; REP(i, g[v].size()) { edge e = g[v][i]; if (p.second.second + e.coin > 300)continue; if (d[e.to][p.second.second + e.coin] > d[v][p.second.second] + e.cost) { d[e.to][p.second.second + e.coin] = d[v][p.second.second] + e.cost; q.push(PP(d[e.to][p.second.second + e.coin], P(e.to, p.second.second + e.coin))); } } } } int main() { cin >> n >> c >> m; vector i1(m), i2(m), i3(m), i4(m); REP(i, m) { cin >> i1[i]; i1[i]--; } REP(i, m) { cin >> i2[i]; i2[i]--; } REP(i, m) cin >> i3[i]; REP(i, m) cin >> i4[i]; REP(i, m) g[i1[i]].push_back({ i2[i],i4[i],i3[i] }); dijkstra(0); REP(i, c + 1)ans = min(ans, d[n - 1][i]); if (ans == INF)cout << -1 << endl; else cout << ans << endl; }