#include using namespace std; using ll = long long; using P = pair; using T = tuple; int main () { int N, M; ll X; cin >> N >> M >> X; std::vector gr[100020]; for (int i = 0; i < M; i ++) { int u, v; ll a, b; cin >> u >> v >> a >> b; gr[--u].emplace_back(b, a, --v); gr[v].emplace_back(b, a, u); } ll ok = -1; ll ng = 1e9 + 7; vector D(N); while (abs(ok - ng) > 1) { ll mu = (ok + ng) / 2; priority_queue, greater

> pque; D.assign(N, X + 100); D[0] = 0; pque.emplace(0, 0); while (!pque.empty()) { auto [l, u] = pque.top(); pque.pop(); if (l != D[u]) continue; for (auto [b, a, v] : gr[u]) { if (b > mu) continue; if (D[v] > D[u] + a) { D[v] = D[u] + a; pque.emplace(D[v], v); } } } if (D[N - 1] > X) { ng = mu; } else { ok = mu; } } cout << ok << endl; }