#include using namespace std; #define all(v) v.begin(),v.end() using ll = long long; using ull = unsigned long long; using vll=vector; using vvll = vector>; using P = pair; using vp=vector>; const ll INF=1ll<<60; ll mod10=1e9+7; ll mod99=998244353; const double PI = acos(-1); #define rep(i,n) for (ll i=0;i=0;--i) #define rep2(i,a,n) for (ll i=a;i=n;--i) template bool chmax(T &a,const T& b){ if(a bool chmin(T &a,const T& b){ if(a>b){ a=b; return true; } return false; } void makeab(ll M,vector>>& ab,map,ll>& mp){ for(int i=0;i>a>>b>>c; a--;b--; ab[a].emplace_back(c,b); ab[b].emplace_back(c,a); ll d; cin>>d; mp[{a,b,c}]=d; mp[{b,a,c}]=d; } } vector di(long long s,vector>>& ab,map,ll>& mp,ll m){ long long N=ab.size(); priority_queue,vector>,greater>> pq; vector dist(N,(1ll<<60)); dist[s]=0; pq.emplace(0,s); while(!pq.empty()){ auto [cost,now]=pq.top();pq.pop(); if(dist[now]>N>>M>>X; vector> ab(N); map,ll> mp; makeab(M,ab,mp); ll l=-1,r=1e10; while(r-l>1){ ll m=(r+l)/2; vll d=di(0,ab,mp,m); if(d[N-1]<=X)l=m; else r=m; } cout << (l==0?-1:l) << endl; }