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
#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
相关文章推荐
- Ubuntu 14中,Foxmail关联163邮箱账号时,总提示“密码错误”的解决方案
- Ain_EditPlus配置安装教程
- mac下Genymotion添加虚拟设备提示 The file is corrupt. Do you want to download the file again?解决方法
- 算法实战(三)--求K-Pairs
- main函数的两个参数
- Greenplum failed segment的恢复方法
- 从零开始,5分钟创建并玩转属于自己的区块链(图文攻略)
- 真机测试遇到 ——is not paired with your computer
- git时认证失败(Authentication failed )的解决
- 安装Ubutun 12.04 遇到the grub-efi-amd64-signed package failed to install into...【解决办法】
- 最新中国菜刀caidao-20160620下载和说明
- 【poj3691-DNA repair】AC自动机+DP
- ubuntu enable all Ubuntu software (main universe restricted multiverse) repositories use
- 8A - Train and Peter
- the user operation is waiting
- Gradle sync failed: Cause: org/gradle/api/publication/maven/internal/DefaultMavenFactory
- 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)
- HDU - 1021 Fibonacci Again
- 树链剖分+线段树 HDOJ 5029 Relief grain(分配粮食)
- Constraint 约束增强说明