#include #include #include using namespace std; class Node { public : int id; int cost; int width; Node() = default; Node( int id, int cost, int width ) : id( id ), cost( cost ), width( width ) {}; bool operator < ( const Node &node ) const { return this->cost < node.cost; } }; int main( void ) { int N, M; long long X; cin >> N >> M >> X; vector> Graph( N + 1 ); int u, v, a, b; int max_width = 0; for( int i = 0; i < M; i++ ) { cin >> u >> v >> a >> b; max_width = max( max_width, b ); Graph[u].push_back( Node( v, a, b ) ); Graph[v].push_back( Node( u, a, b ) ); } int left = 0, right = max_width + 1; int mid; vector shortest( N + 1 ); while( left < right ) { mid = ( left + right ) / 2 + 1; shortest.assign( N + 1, -1 ); priority_queue, vector>, greater>> q; shortest[1] = 0; q.push( make_pair( 0, 1 ) ); pair cur; while( !q.empty() ) { cur = q.top(), q.pop(); if( cur.first > shortest[cur.second] ) continue; for( Node next : Graph[cur.second] ) { if( next.width >= mid && ( shortest[next.id] == -1 || shortest[next.id] > shortest[cur.second] + next.cost ) ) { shortest[next.id] = shortest[cur.second] + next.cost; q.push( make_pair( shortest[next.id], next.id ) ); } } } if( shortest[N] == -1 || shortest[N] > X ) { right = mid - 1; } else { left = mid; } } if( left == 0 ) { cout << -1 << endl; } else { cout << left << endl; } return 0; }