#include #include #include #include #include #include #include #include #define rep(i, a) FOR(i, 0, a) #define FOR(i, a, b) for(int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair P; struct edge{ int to, time, cost; }; const int max = 51; const int inf = (int)1e+9; int n, c; P cost[max]; std::vector node[max]; void dijkstra(int s){ std::priority_queue, std::greater

> que; rep(i, n)cost[i].first = inf, cost[i].second = inf; cost[s].first = 0, cost[s].second = 0; que.push(P(0, s)); while (!que.empty()){ P p = que.top(); que.pop(); if (cost[p.second].first < p.second)continue; rep(i, node[p.second].size()){ edge e = node[p.second][i]; if (p.first + e.time < cost[e.to].first && cost[p.second].second + e.cost <= c){ cost[e.to].first = p.first + e.time; cost[e.to].second = cost[p.second].second + e.cost; que.push(P(cost[e.to].first, e.to)); } } } } int main(){ int v; int s[51], t[51], y[51], m[51]; std::cin >> n >> c >> v; rep(i, n)std::cin >> s[i]; rep(i, n)std::cin >> t[i]; rep(i, n)std::cin >> y[i]; rep(i, n)std::cin >> m[i]; rep(i, n){ edge a; a.to = t[i] - 1; a.cost = y[i]; a.time = m[i]; node[s[i] - 1].push_back(a); } dijkstra(0); std::cout << (cost[n - 1].first == inf ? -1 : cost[n - 1].first) << std::endl; return 0; }