#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } ll dijk(int n, vector>> &ikeru){ const ll inf = (1e18) + 50; vector d(n, inf); d[0] = 0; priority_queue> pq; pq.push(pair(0, 0)); while(!pq.empty()){ auto [tmp, i] = pq.top(); pq.pop(); tmp = -tmp; if (tmp > d[i]) continue; for (auto [j, dist] : ikeru[i]){ ll targ = dist + tmp; if (targ < d[j]){ d[j] = targ; pq.push(pair(-targ, j)); } } } return d[n-1]; } int main(){ int n, m; cin >> n >> m; ll x; cin >> x; //vector ikeru(n, vector>(0)); vector> edge; rep(i,0,m){ int u, v; cin >> u >> v; u--; v--; ll a, b; cin >> a >> b; edge.push_back(make_tuple(u, v, a, b)); } int lb = -1; int ub = 1e9 + 6; while (ub - lb > 1){ int targ = (lb + ub) / 2; vector ikeru(n, vector>(0)); for (auto [u, v, a, b] : edge){ if (b >= targ){ ikeru[u].push_back(pair(v, a)); ikeru[v].push_back(pair(u, a)); } } //cout << dijk(n, ikeru) << " " << x << " " << targ << '\n'; if (dijk(n, ikeru) <= x){ lb = targ; }else{ ub = targ; } } cout << lb << '\n'; }