#include using namespace std; struct Edge{ int to; long long cost; long long cap; }; using Graph = vector>; using Pair = pair; void Dijkstra(const Graph& graph, vector& distances, int startIndex, int cap){ priority_queue, greater> q; q.emplace((distances[startIndex] = 0), startIndex); while (!q.empty()){ const long long distance = q.top().first; const int from = q.top().second; q.pop(); if (distances[from] < distance)continue; for (const auto& edge : graph[from]){ const long long d = (distances[from] + edge.cost); if (d < distances[edge.to] and edge.cap >= cap){ q.emplace((distances[edge.to] = d), edge.to); } } } } int main() { int N, M; long long X; cin >> N >> M >> X; Graph G(N); for (int i = 0; i < M; i++){ int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; G[u].push_back({v, a, b}); G[v].push_back({u, a, b}); } int l = -1, r = 1e9 + 10; while (r - l > 1){ int mid = l + (r - l) / 2; vector d(N, (long long) 1e15); Dijkstra(G, d, 0, mid); if (d[N - 1] <= X){ l = mid; } else { r = mid; } } cout << l << '\n'; }