#include #include #include #include #include #include #include #include #include #include #include #define INF 1000000000 typedef long long ll; using namespace std; int main() { // source code int N, C, V; cin >> N >> C >> V; vector S(V), G(V), Y(V), M(V); for (int i = 0; i < V; i++) { cin >> S[i]; } for (int i = 0; i < V; i++) { cin >> G[i]; } for (int i = 0; i < V; i++) { cin >> Y[i]; } for (int i = 0; i < V; i++) { cin >> M[i]; } vector > > > edge(N); for (int i = 0; i < V; i++) { edge[S[i] - 1].push_back(make_pair(G[i] - 1, make_pair(Y[i], M[i]))); } vector > dp(N, vector(C + 1)); // vertex, cost for (int i = 0; i < N; i++){ for (int j = 0; j < C + 1; j++){ dp[i][j] = INF; } } dp[0][C] = 0; for (int i = 0; i < N; i++){ for (int j = 0; j < C + 1; j++){ if (dp[i][j] == INF || edge[i].empty()) continue; for(int k = 0; k < edge[i].size(); k++){ if (j - edge[i][k].second.second >= 0) { dp[edge[i][k].first][j - edge[i][k].second.first] = min(dp[edge[i][k].first][j - edge[i][k].second.first], dp[i][j] + edge[i][k].second.second); } } } } int ret = INF; for (int i = 0; i < C + 1; i++){ ret = min(ret, dp[N - 1][i]); } if (ret == INF) { cout << -1 << endl; } else{ cout << ret << endl; } return 0; }