#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; template std::vector dijkstra(std::vector>>& to, int s=0) { const unsigned long long INF = 1002003004005006007; struct QueElem { int v; unsigned long long c; bool operator<(const QueElem a) const {return c > a.c;} QueElem(int v, unsigned long long c): v(v), c(c) {} }; std::priority_queue q; std::vector dist(to.size(), INF); dist[s] = 0; q.emplace(s, 0); while(!q.empty()) { QueElem qe = q.top(); q.pop(); int u = qe.v; unsigned long long c = qe.c; if (c > dist[u]) continue; for(auto vc: to[u]) { int v = vc.first; unsigned long long nc = c + vc.second; if (nc < dist[v]) { dist[v] = nc; q.emplace(v, nc); } } } return dist; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; ll x; cin >> n >> m >> x; struct E { int u, v, a, b; }; vector es(m); for(auto& [u, v, a, b] : es) { cin >> u >> v >> a >> b; u--, v--; } sort(all(es), [](const E& x, const E& y) { return x.b > y.b; }); int l = 0, r = m + 1; vector> to(n); while(r - l > 1) { int c = (l + r) / 2; rep(i, n) to[i].clear(); rep(i, c) { auto [u, v, a, b] = es[i]; to[u].emplace_back(v, a); to[v].emplace_back(u, a); } (dijkstra(to)[n - 1] <= x ? r : l) = c; } int ans = r == m + 1 ? -1 : es[r - 1].b; cout << ans << '\n'; }