#include using namespace std; typedef struct{ int corrent; int next; int money; int tim; }ROOT; int N, C, V; ROOT root[1500]; int dp[50][300] = {{0}}; int result = INT_MAX; void rec(int corrent = 1, int money = 0, int tim = 0){ if(money > C) return; if(corrent == N){ if(result > tim) result = tim; return; } if(dp[corrent][money] != 0 && dp[corrent][money] <= tim && result <= tim) return; dp[corrent][money] = tim; for(int i = 0; i < V; ++i){ if(root[i].corrent == corrent) rec(root[i].next, money + root[i].money, tim + root[i].tim); } return; } int main(void){ cin >> N >> C >> V; int i; for(i = 0; i < V; ++i) cin >> root[i].corrent; for(i = 0; i < V; ++i) cin >> root[i].next; for(i = 0; i < V; ++i) cin >> root[i].money; for(i = 0; i < V; ++i) cin >> root[i].tim; rec(); if(result == INT_MAX) cout << -1 << endl; else cout << result << endl; return 0; }