您的位置:首页 > 大数据 > 人工智能

HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)

2016-07-18 13:14 453 查看
思路:把容量排序之后,二分容量然后最短路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
<=t)
return true;
else
return false;
// return d
<=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);
}
}


Description

Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with 1 corresponds to a mine from where some precious minerals are extracted. The vertex numbered with N corresponds to a minerals
processing factory. Each edge has an associated travel time (in time units) and capacity (in units of minerals). It has been decided that the minerals which are extracted from the mine will be delivered to the factory using a single path. This path should
have the highest capacity possible, in order to be able to transport simultaneously as many units of minerals as possible. The capacity of a path is equal to the smallest capacity of any of its edges. However, the minerals are very sensitive and, once extracted
from the mine, they will start decomposing after T time units, unless they reach the factory within this time interval. Therefore, the total travel time of the chosen path (the sum of the travel times of its edges) should be less or equal to T. 

 

Input

The first line of input contains an integer number X, representing the number of test cases to follow. The first line of each test case contains 3 integer numbers, separated by blanks: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and
T (1 <= T <= 500.000). Each of the next M lines will contain four integer numbers each, separated by blanks: A, B, C and D, meaning that there is an edge between vertices A and B, having capacity C (1 <= C <= 2.000.000.000) and the travel time D (1 <= D <=
50.000). A and B are different integers between 1 and N. There will exist at most one edge between any two vertices. 

 

Output

For each of the X test cases, in the order given in the input, print one line containing the highest capacity of a path from the mine to the factory, considering the travel time constraint. There will always exist at least one path
between the mine and the factory obbeying the travel time constraint. 

 

Sample Input

2
2 1 10
1 2 13 10
4 4 20
1 2 1000 15
2 4 999 6
1 3 100 15
3 4 99 4

 

Sample Output

13
99

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: