#include #include using namespace atcoder; using namespace std; using ll=int; using ld=long double; ld pie=3.141592653589793; ll mod=998244353 ; long long inf=10000999999999900; int main(){ ll n,m,x; cin >> n >> m >> x; vector>>>g(n); for (ll i = 0; i < m; i++) { long long 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}}); } ll left=0,right=1000000001; while (right-left>1) { ll mid=(right+left)/2; priority_queue,vector>,greater>>pq; pq.push({0,0}); vectormemo(n,inf); memo[0]=0; while (!pq.empty()) { ll v=pq.top().second; pq.pop(); if (memo[v]>=x) { continue; } for (ll j = 0; j < g[v].size(); j++) { if (g[v][j].second.secondmemo[v]+g[v][j].second.first) { memo[g[v][j].first]=memo[v]+g[v][j].second.first; pq.push({memo[g[v][j].first],g[v][j].first}); } } } if (memo[n-1]>x) { right=mid; }else{ left=mid; } } if (left==0) { cout << -1 << endl; return 0; } cout << left << endl; }