#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } vector dijkstra(Graph& G,int s){ int n=G.size(); vector dist(n,INF); dist[s]=0; priority_queue,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m,x; cin>>n>>m>>x; vector U(m),V(m),A(m),B(m); rep(i,m){ cin>>U[i]>>V[i]>>A[i]>>B[i]; U[i]--,V[i]--; } ll ok=0,ng=1e9+7; while(ng-ok>1){ ll mid=(ok+ng)/2; Graph G(n); rep(i,m){ if(B[i] dis=dijkstra(G,0); if(dis[n-1]>x) ng=mid; else ok=mid; } if(ok==0) cout<<-1<