#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll INF = 2e+18; typedef pair P; struct edge{ int to; ll cost; edge(int to, ll cost): to(to), cost(cost) {} }; vector dijkstra(int s, vector> G){ priority_queue, greater

> que; int n = G.size(); vector d(n, INF); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top();que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if(d[v] + e.cost < d[e.to]){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } return d; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; ll x; cin >> n >> m >> x; vector u(m), v(m); vector a(m), b(m); for(int i = 0; i < m; i++){ cin >> u[i] >> v[i] >> a[i] >> b[i]; u[i]--; v[i]--; } auto judge = [&](int s){ vector> g(n); for(int i = 0; i < m; i++){ if(b[i] >= s){ g[u[i]].push_back(edge(v[i], a[i])); g[v[i]].push_back(edge(u[i], a[i])); } } auto d = dijkstra(0, g); return d[n-1] <= x; }; if(!judge(0)){ cout << -1 << endl; return 0; } ll l = 0, r = 1e9+5; while(r-l > 1){ ll x = (l+r)/2; if(judge(x)) l = x; else r = x; } cout << l << endl; }