#include #include using namespace std; #define rep(i, n) for(int i=0; i #include int main() { int N, C, V; cin >> N >> C >> V; vector>> path(N); vector> memo(V, vector(4)); rep(i, 4) { rep(j, V) { cin >> memo[j][i]; } } rep(i, V) { int s = memo[i][0] - 1; int t = memo[i][1] - 1; int y = memo[i][2]; int m = memo[i][3]; path[s].push_back({ t,y,m }); } priority_queue < vector, vector>, greater>> pq; vector ans = { (mod,mod) }; queue> q; q.push({ 0, 0, 0 }); while (!q.empty()) { int now = q.front()[0]; int time = q.front()[1]; int cost = q.front()[2]; q.pop(); for (vector v : path[now]) { int x = v[0]; int nt = time + v[2]; int nc = cost + v[1]; if (nc > C) { continue; } if (x == N - 1&&nt