#include using namespace std; typedef long long ll; #define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rrep(i,a,b) for(ll i=(ll)(a-1);i>=(ll)(b);i--) #define MOD 998244353 #define INF 1e16 template bool chmax(T& a,T b){if(a bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} ll comb(ll x,ll y){ ll ans=1; rep(i,0,y) ans*=(x-i); rep(i,0,y) ans/=(i+1); return ans; } ll rui(ll x){ if(x==0) return 1; return 2*rui(x-1); } ll fac(ll x){ if(x==0) return 1; return x*fac(x-1); } ll pow(ll x,ll n){ ll ans=1; while(n>0){ if(n&1) ans*=x; x*=x; n>>=1; } return ans; } ll n,m,x; vector>>> g; bool dijkstra(vector>>>& g,ll h){ vector d(n,1e18); priority_queue>,vector>>,greater>>> pq; pq.push({0,{0,1e18}}); while(!pq.empty()){ ll x=pq.top().first,y=pq.top().second.first,z=pq.top().second.second; if(d[y]>x){ d[y]=x; for(auto&& [p,q]:g[y]){ if(q.second> n >> m >> x; vector u(m),v(m),a(m),b(m); g.resize(n); rep(i,0,m){ cin >> u[i] >> v[i] >> a[i] >> b[i]; u[i]--,v[i]--; g[u[i]].push_back({v[i],{a[i],b[i]}}); g[v[i]].push_back({u[i],{a[i],b[i]}}); } ll p=-1,q=1e9; while(q-p>1){ ll r=(p+q)/2; if(dijkstra(g,r)) p=r; else q=r; } cout << p << endl; }