#include #include using namespace std; using ll = long long; const ll inf=9e18; int main(){ ll n,m,x; cin >> n >> m >> x; vector>> g(n); for(ll i=0;i> u >> v >> a >> b; u--, v--; g[u].push_back({v,a,b}); g[v].push_back({u,a,b}); } ll ng=1e18+2,ok=-1; while(ng-ok>1){ ll m=(ok+ng)/2; vector total_cost(n,inf); total_cost[0]=0; priority_queue,vector>,greater>> q; q.push({0,0}); while(q.size()){ auto[cost,now]=q.top(); q.pop(); if(total_cost[now]b) continue; if(total_cost[next]<=total_cost[now]+a) continue; total_cost[next]=total_cost[now]+a; q.push({total_cost[next],next}); } } if(total_cost[n-1]<=x) ok=m; else ng=m; } if(ok==0) cout << -1; else cout << ok; }