#include #include #include #include #include using namespace std; using P = pair; using T = tuple; const int INF = 1e9; int N, M, X; vector G[100005]; int dist[100005]; bool check(int mid) { fill(dist, dist+N+1, INF); priority_queue, greater

> que; dist[1] = 0; que.push(P(0, 1)); while(!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if(dist[v] < p.first) continue; for(auto &[u, a, b] : G[v]) { if(b < mid) continue; if(dist[u] > dist[v] + a) { dist[u] = dist[v] + a; que.push(P(dist[u], u)); } } } return dist[N] <= X; } int main() { cin >> N >> M >> X; for(int i = 0; i < M; ++i) { int u, v, a, b; cin >> u >> v >> a >> b; G[u].push_back(T(v, a, b)); G[v].push_back(T(u, a, b)); } int l = 0, r = 1e18+1; while(r - l > 1) { int mid = (l + r) / 2; if(check(mid)) l = mid; else r = mid; } if(l==0) cout << -1 << endl; else cout << l << endl; return 0; }