#include using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; long long f; cin >> n >> m >> f; vector x(m), y(m), a(m), b(m); vector> g(n); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> a[i] >> b[i]; x[i]--; y[i]--; g[x[i]].emplace_back(i); g[y[i]].emplace_back(i); } int low = -1, high = 1e9 + 10; while (high - low > 1) { auto mid = (high + low) >> 1; vector d(n, f + 1); priority_queue, vector>, greater>> pq; d[0] = 0; pq.emplace(d[0], 0); while (!pq.empty()) { auto [dv, v] = pq.top(); pq.pop(); if (d[v] != dv) { continue; } for (int id : g[v]) { int to = x[id] ^ y[id] ^ v; if (b[id] < mid) { continue; } long long cost = d[v] + a[id]; if (d[to] > cost) { d[to] = cost; pq.emplace(d[to], to); } } } if (d[n - 1] <= f) { low = mid; } else { high = mid; } } cout << low << '\n'; return 0; }