#include using namespace std; const int INF = 1e9; int S[1500]; int T[1500]; int Y[1500]; int M[1500]; int dist[51][301]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N,C,V; cin >> N; cin >> C; cin >> 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=1;i<=N;i++) { for(int j=0;j<=C;j++) { dist[i][j] = 1e9; } } dist[1][0] = 0; priority_queue >,vector>>,greater>>> pque; pque.push(make_pair(dist[1][0],make_pair(1,0))); while(!pque.empty()) { int now = pque.top().second.first; int cost = pque.top().second.second; if(dist[now][cost] < pque.top().first) { pque.pop(); continue; } pque.pop(); for(int i=0;i dist[now][cost] + M[i]) { dist[T[i]][cost+Y[i]] = dist[now][cost] + M[i]; pque.push(make_pair(dist[T[i]][cost+Y[i]],make_pair(T[i],cost+Y[i]))); } } } } } int res = 1e9; for(int i=0;i<=C;i++) { res = min(res,dist[N][i]); } if(res==1e9) { res = -1; } cout << res << '\n'; return 0; }