#include #include #include #include using namespace std; typedef tuple Tp; const int INF = 1 << 28; int N, C, V; int S[1555], T[1555], Y[1555], M[1555]; vector> graph[55]; int dp[55][333]; int solve(){ for(int i=0;i, greater> Q; dp[0][C] = 0; Q.push(Tp(0, 0, C)); while(!Q.empty()){ auto t = Q.top(); Q.pop(); int d = get<0>(t), v = get<1>(t), c = get<2>(t); for(auto edge : graph[v]){ int u = get<0>(edge); int next_cost = c - get<1>(edge); int next_dist = d + get<2>(edge); if(next_cost < 0)continue; if(next_dist < dp[u][next_cost]){ dp[u][next_cost] = next_dist; Q.push(Tp(next_dist, u, next_cost)); } } } int res = INF; for(int c=0;c<=C;c++)res = min(res, dp[N-1][c]); if(res == INF)res = -1; return res; } int main(){ cin >> N >> C >> V; for(int i=0;i> S[i]; for(int i=0;i> T[i]; for(int i=0;i> Y[i]; for(int i=0;i> M[i]; for(int i=0;i