#include #include #include #include #include #include #include #include using namespace std; struct Road { int destination; int cost; int time; Road() : destination(0), cost(0), time(0) {} Road(int d, int c, int t) : destination(d), cost(c), time(t) {} }; std::vector> road; std::vector>> dp; enum { arrival_time = 0, minimum_time = 1 }; int solve(int start, int goal, int money, int time) { if(money < 0) return -1; if(start == goal) return time; if(road[start].empty()) return -1; if(get(dp[start][money]) != -2 && get(dp[start][money]) < time) return get(dp[start][money]); int min=INT_MAX; for(const auto &r : road[start]) { int t = solve(r.destination, goal, money-r.cost, time+r.time); if(t < min && t != -1) min = t; } if(min == INT_MAX) min = -1; dp[start][money] = make_tuple(time, min); return min; } int main() { int N, C, V; cin >> N >> C >> V; std::vector S(V), T(V), Y(V), M(V); for(auto & s : S) cin >> s; for(auto & t : T) cin >> t; for(auto & y : Y) cin >> y; for(auto & m : M) cin >> m; road.resize(N+1); for(int i=0; i