#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, m, x, ok = -1, ng = 1ll << 30, mid; cin >> n >> m >> x; vector> edge(m); for(int i = 0; i < m; i++){ ll a, b, c, d; cin >> a >> b >> c >> d; a--, b--; edge[i] = make_tuple(a, b, c, d); } while(ok + 1 < ng){ mid = (ok + ng) / 2; vector>> g(n); for(int i = 0; i < m; i++){ ll a, b, c, d; tie(a, b, c, d) = edge[i]; if(d < mid) continue; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } priority_queue, vector>, greater>> pq; vector dist(n, 1ll << 60); pq.emplace(0, 0); dist[0] = 0; while(!pq.empty()){ ll d, c; int v, u; tie(d, v) = pq.top(); pq.pop(); if(dist[v] > d) continue; for(auto &&pa : g[v]){ tie(u, c) = pa; if(d + c >= dist[u]) continue; dist[u] = d + c; pq.emplace(d + c, u); } } (dist[n - 1] <= x ? ok : ng) = mid; } cout << ok << '\n'; }