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

 

Delay Constrained Maximum Capacity Path

 

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

 

 

Problem 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 Output13 99

 

题目大意:有一个n个点,m个边的图,1号点有矿物,n号点是加工厂,每条路有通行时间和运载量,总运载量等于你选的路径中最小的运载量,求1到n用时不超过T时最大的运载量。

记录下最小的运载量和最大的运载量,最后的答案肯定就在这之间,用二分求出即可

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int maxm=5e4+7;
const int maxn=1e4+7;
const int inf=0x3f3f3f3f;
typedef pair<int,int> P;
struct Node
{
	int to;
	int next;
	int time;
	int capa;
}edge[maxm<<1];
int cnt,n,m,t;
int head[maxn];
int dis[maxn];
void init()
{
	memset(head,-1,sizeof(head));
	cnt=0;
	return;
}
void add(int u,int v,int capa,int time)
{
	edge[cnt].to=v;
	edge[cnt].capa=capa;
	edge[cnt].time=time;
	edge[cnt].next=head[u];
	head[u]=cnt++;
	return;
}
bool dijkstra(int limit,int time)
{
	priority_queue<P,vector<P>,greater<P> > que;
	memset(dis,inf,sizeof(dis));
	dis[1]=0;
	que.push(make_pair(1,dis[1]));
	while(!que.empty())
	{
		P now=que.top();
		que.pop();
		int node=now.first;
		int tmp_dis=now.second;
		if(dis[node]<tmp_dis) continue;
		for(int i=head[node];~i;i=edge[i].next)
		{
			int v=edge[i].to;
			if(edge[i].capa>=limit&&dis[v]>dis[node]+edge[i].time)
			{
				dis[v]=dis[node]+edge[i].time;
				que.push(make_pair(v,dis[v]));
			}
		}
	}
	return dis[n]<=time;
}
int main()
{
	int test;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d%d%d",&n,&m,&t);
		init();
		int left=inf,right=-1;
		for(int i=0;i<m;i++)
		{
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			add(a,b,c,d);
			add(b,a,c,d);
			left=min(left,c);
			right=max(right,c);
		}
		int ans;
		while(left<=right)
		{
			int mid=(left+right)>>1;
			if(dijkstra(mid,t))
			{
				left=mid+1;
				ans=mid;
			}
			else right=mid-1;
		}
		cout<<ans<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值