#include #include #include long N,M,X; std::vector>>G[1<<17]; long dist[1<<17]; std::priority_queue>Q; int main() { std::cin>>N>>M>>X; for(int i=0;i>u>>v>>a>>b; u--,v--; G[u].push_back(std::make_pair(v,std::make_pair(a,b))); G[v].push_back(std::make_pair(u,std::make_pair(a,b))); } int L=0,R=1e9+1; while(R-L>1) { int mid=(L+R)/2; for(int i=1;ic)continue; for(std::pair>p:G[u]) { int v=p.first; auto[a,b]=p.second; if(bX)continue; if(dist[v]>dist[u]+a) { dist[v]=dist[u]+a; Q.push({-dist[v],v}); } } } if(dist[N-1]!=(long)1e18)L=mid; else R=mid; } if(L==0)L=-1; std::cout<