#include #include int main() { int N, C, V; std::cin >> N; std::cin >> C; std::cin >> V; std::vector S(V), T(V), Y(V), M(V); for (int i = 0; i < V; i++) { std::cin >> S[i]; S[i] -= 1; } for (int i = 0; i < V; i++) { std::cin >> T[i]; T[i] -= 1; } for (int i = 0; i < V; i++) { std::cin >> Y[i]; } for (int i = 0; i < V; i++) { std::cin >> M[i]; } const int INF = 100000; std::vector> dp(N, std::vector(C + 1, INF)); dp.at(0).at(0) = 0; struct Edge { int t; int y; int m; }; std::vector> G(N, std::vector()); for (int i = 0; i < V; i++) { Edge edge{T.at(i), Y.at(i), M.at(i)}; G.at(S.at(i)).push_back(edge); } for (int s = 0; s < N; s++) { for (int c = 0; c < C; c++) { if (dp.at(s).at(c) == INF) { continue; } for (const auto &edge: G.at(s)) { if (c + edge.y > C) { continue; } if (dp.at(edge.t).at(c + edge.y) > dp.at(s).at(c) + edge.m) { dp.at(edge.t).at(c + edge.y) = dp.at(s).at(c) + edge.m; } } } } int ans = INF; for (const auto &x: dp.at(N - 1)) { if (ans > x) { ans = x; } } if (ans == INF) { ans = -1; } std::cout << ans << std::endl; }