#include #include #include #include #include using namespace std; struct Edge { Edge(int source, int cost, int time) : source(source), cost(cost), time(time) {} int source; int cost; int time; }; map > destToEdges; int main() { int n, c, v; cin >> n >> c >> v; vector s(v); for (int i = 0; i < v; ++i) { cin >> s[i]; } vector t(v); for (int i = 0; i < v; ++i) { cin >> t[i]; } vector y(v); for (int i = 0; i < v; ++i) { cin >> y[i]; } vector m(v); for (int i = 0; i < v; ++i) { cin >> m[i]; } for (int i = 0; i < v; ++i) { destToEdges[t[i]].push_back(Edge(s[i], y[i], m[i])); } static int minTimes[51][301]; // [city][cost] minTimes[1][0] = 0; for (int cost = 1; cost <= c; ++cost) { minTimes[1][cost] = numeric_limits::max(); } for (int city = 2; city <= n; ++city) { for (int cost = 0; cost <= c; ++cost) { minTimes[city][cost] = numeric_limits::max(); for (vector::const_iterator it = destToEdges[city].begin(); it != destToEdges[city].end(); ++it) { if (it->cost <= cost && minTimes[it->source][cost - it->cost] != numeric_limits::max()) { minTimes[city][cost] = min(minTimes[city][cost], minTimes[it->source][cost - it->cost] + it->time); } } } } int minTime = numeric_limits::max(); for (int cost = 0; cost <= c; ++cost) { minTime = min(minTime, minTimes[n][cost]); } cout << ((minTime == numeric_limits::max()) ? -1 : minTime) << endl; return 0; }