#include // #include "atcoder/modint" using i64 = long long; // using Fp = atcoder::modint998244353; constexpr i64 inf = 1ll << 60; struct Edge { int to; i64 cost; i64 width; }; int main() { int N, M; i64 X; std::cin >> N >> M >> X; std::vector U(M), V(M); std::vector A(M), B(M); std::vector> graph(N); for (int i = 0; i < M; ++i) { std::cin >> U[i] >> V[i]; --U[i], --V[i]; std::cin >> A[i] >> B[i]; graph[U[i]].push_back({V[i], A[i], B[i]}); graph[V[i]].push_back({U[i], A[i], B[i]}); } i64 ok = -1, ng = 1ll << 60; auto calcDist = [&](i64 m) { std::vector dist(N, inf); dist[0] = 0; std::priority_queue, std::vector>, std::greater>> pq; pq.push({0, 0}); while (not pq.empty()) { const auto [nd, f] = pq.top(); pq.pop(); if (nd > dist[f]) continue; for (const auto &[t, c, w] : graph[f]) { if (w < m) continue; if (dist[t] > dist[f] + c) { dist[t] = dist[f] + c; pq.push({dist[t], t}); } } } return dist[N - 1]; }; while (ng - ok > 1) { const auto mid = (ok + ng) / 2; if (calcDist(mid) <= X) ok = mid; else ng = mid; } std::cout << ok << std::endl; }