思路:把容量排序之后,二分容量然后最短路check就好了
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 10000+500;
int n,m,t;
struct Node
{
int v,t;
LL c;
Node(){};
Node(int vv,LL cc,int tt):v(vv),c(cc),t(tt){};
};
vector<Node>e[maxn];
int d[maxn];
LL cc[maxn*6];
int inq[maxn];
bool check(LL limit)
{
for(int i = 0;i<=n;i++)
d[i]=9999999;
memset(inq,0,sizeof(inq));
d[1]=0;
queue<int>q;
q.push(1);
inq[1]=1;
while(!q.empty())
{
int u = q.front();
q.pop();
inq[u]=0;
for(int i = 0;i<e[u].size();i++)
{
Node v = e[u][i];
if(v.c < limit)
continue;
if(d[v.v] > d[u]+v.t)
{
d[v.v] = d[u]+v.t;
if(!inq[v.v])
q.push(v.v);
inq[v.v]=1;
}
}
}
if(d[n]<=t)
return true;
else
return false;
// return d[n]<=t;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&t);
for(int i = 0;i<=n;i++)
e[i].clear();
memset(cc,0,sizeof(cc));
for(int i = 0;i<m;i++)
{
int u,v,tt;
LL c;
scanf("%d%d%lld%d",&u,&v,&c,&tt);
cc[i]=c;
e[u].push_back({v,c,tt});
e[v].push_back({u,c,tt});
}
sort(cc,cc+m);
int ans = 0;
int l = 0,r=m-1;
while(l<=r)
{
int mid = (l+r)/2;
if(check(cc[mid]))
l = mid+1,ans = cc[mid];
else
r = mid-1;
}
printf("%lld\n",ans);
}
}