1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<ctime> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } const int maxn=100005; int n,m,t,dist[maxn],vst[maxn],a[maxn]; struct Edge { int from,to,dist,v2; }; vector<Edge>edges[maxn]; void AddEdge(int x,int y,int v,int v2) { edges[x].push_back((Edge) { x,y,v,v2 }); } struct HeapNode { int d,u; bool operator < (const HeapNode& b) const { return d>b.d; } }; void Dijkstra(int s,int Limit=0) { priority_queue<HeapNode>Q; memset(vst,0,sizeof(vst)); for(int i=1; i<=n; i++)dist[i]=0x7fffffff/2; Q.push((HeapNode) { 0,s }); dist[s]=0; while(!Q.empty()) { int Now=Q.top().u; Q.pop(); if(vst[Now])continue; vst[Now]=1; for(int i=0; i<edges[Now].size(); i++) { Edge& e=edges[Now][i]; int Next=e.to; if(e.v2<=Limit)continue; if(dist[Next]>dist[Now]+e.dist) { dist[Next]=dist[Now]+e.dist; Q.push((HeapNode) { dist[Next],Next }); } } } } bool Check(int Limit) { Dijkstra(1,Limit); return dist[n]>=t; } int main() { n=Get_Int(); m=Get_Int(); t=Get_Int(); for(int i=1; i<=m; i++) { int x=Get_Int(),y=Get_Int(),v=Get_Int(),v2=Get_Int(); AddEdge(x,y,v,v2); a[i]=v2; } Dijkstra(1); if(dist[n]>=t) { printf("-1 %d\n",dist[n]); return 0; } sort(a+1,a+m+1); int Left=0,Right=unique(a+1,a+m+1)-(a+1); while(Left<=Right) { int mid=(Left+Right)>>1; if(Check(a[mid]))Right=mid-1; else Left=mid+1; } printf("%d\n",a[Left]); return 0; }
|