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

HDU 1839 Delay Constrained Maximum Capacity Path

2016-04-21 18:54 423 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1839

Delay Constrained Maximum Capacity Path

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1242    Accepted Submission(s): 387


[align=left]Problem Description[/align]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.
 
[align=left]Input[/align]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.
 
[align=left]Output[/align]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.
 
[align=left]Sample Input[/align]
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 
[align=left]Sample Output[/align]
13
99 
[align=left]Author[/align]Mugurel Ionut Andreica 
[align=left]Source[/align]Politehnica University of Bucharest Local Team Contest 2007 
[align=left]Recommend[/align]lcy   |   We have carefully selected several similar problems for you:  4114 3986 1162 1841 4063 这道题的大意是:有n个点 m条路,给出n,m,T ,T为限制时间,然后给出m个A B C D ,A:起点 B:终点 C:运输能力 D:从A到B的时间。求从1到n的的一条路径使得总时间小于=T,且运输能力最大。解题思路:考虑到要求运输能力最大,且运输能力受到道路的限制,我们可以按道路的运输能力排序,然后进行枚举求最短时间看时间是否小于T,为了不超时,我们用二分。代码如下:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>

#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
#define maxn 10005
#define maxm 50005
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
}
struct node
{
int v,w,next,cap;
}edge[2*maxm];
int n,m,T,limit;
int pre[maxn];
int vis[maxn];
int dist[maxn];
int cap[maxm];
void init()
{
memset(pre,-1,sizeof pre);
int Index=1;
int i;
int x,y,w;
for(i=1;i<=m;i++)///建图的过程
{
scanf("%d%d%d%d",&x,&y,&cap[i],&w);
edge[Index].v=y;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[x];///一条边就让他指向-1
pre[x]=Index++;
edge[Index].v=x;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[y];
pre[y]=Index++;
}
}
int spfa()
{
int start=1;
int end=n;
queue<int>q;
fill(dist+1,dist+maxn+1,INF);///初始化dist为INF
cle(vis);
dist[start]=0;
vis[start]=1;
q.push(start);
while(!q.empty())
{
int top=q.front();
q.pop();
vis[top]=0;///清为零
for(int j=pre[top];j!=-1;j=edge[j].next)
{
int e=edge[j].v;///边终点
if(edge[j].cap>=limit)///如果cap大于limit则进行判断。否则不更新
if(dist[e]>edge[j].w+dist[top])
{
dist[e]=edge[j].w+dist[top];
if(!vis[e])
{
q.push(e);
vis[e]=1;
}
}
}
}
return dist
;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>T;
init();
sort(cap+1,cap+1+m,cmp);
int low=1,high=m;
while(low<high)
{
int mid=(low+high)>>1;
limit=cap[mid];
int tmp=spfa();
if(tmp==INF||tmp>T)
low=mid+1;
else
high=mid;
}
cout<<cap[low]<<endl;
}
return 0;
}

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