#include #include #include using namespace std; int N,M; long X; vector > >G[1<<17]; long D[1<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M>>X; for(int i=0;i>u>>v>>a>>b; u--,v--; G[u].push_back(make_pair(v,make_pair(a,b))); G[v].push_back(make_pair(u,make_pair(a,b))); } int L=0,R=(int)1e9+1; while(R-L>1) { int mid=(L+R)/2; for(int i=1;i >Q; Q.push(make_pair(0,0)); while(!Q.empty()) { int u=Q.top().second; long d=-Q.top().first; Q.pop(); if(D[u] >e:G[u])if(e.second.second>=mid) { int v=e.first; long nd=d+e.second.first; if(D[v]>nd) { D[v]=nd; Q.push(make_pair(-nd,v)); } } } if(D[N-1]<=X)L=mid; else R=mid; } cout<<(L==0?-1:L)<