HDU - 1839 Delay Constrained Maximum Capacity Path(二分+dijkstra)

题目链接: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): 2157    Accepted Submission(s): 731


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 Output
  
  
13 99
 

Author
Mugurel Ionut Andreica

题目要求求规定时间内从1到n的经过最小路容量的最大值

很明显这种类型的就是二分了

而这种套路一般都是对结果二分

也就是对容量二分

对于djkstra 在每次判断的时候加上对二分条件的判断限制 就可以根据结果判定此次二分的条件能不能找到一条符合最小容量大于当前mid的路径 

满足单调性

因为写成ans=l找了好久错误。。

#include <bits/stdc++.h>
using namespace std;
long long int  n,m,ttime;
struct xjy
{
	long long int  num;
	long long int  time;
	long long int  val;
	bool operator < (const xjy &r)const
	{
		return time>r.time;
	}
};
vector<xjy > mmap[11111];
long long int  djkstra(long long int  limit)
{
	long long int  book[11111];
	long long int  dis[11111];
	for(long long int  i=0;i<11111;i++)
	{
		book[i]=0;
		dis[i]=99999999;
	}
	dis[1]=0;
	xjy mid;
	mid.num=1;
	mid.val=0;
	mid.time=0;
	priority_queue<xjy > q;
	q.push(mid);
	while(!q.empty())
	{
		mid=q.top();
		q.pop();
		if(book[mid.num])
			continue;
		book[mid.num]=1;
		for(long long int  i=0;i<mmap[mid.num].size();i++)
		{
			long long int  now=mid.num;
			if(dis[mmap[now][i].num]>dis[now]+mmap[now][i].time&&limit<=mmap[now][i].val)
			{
				dis[mmap[now][i].num]=dis[now]+mmap[now][i].time;
				xjy midmid;
				midmid.num=mmap[now][i].num;
				midmid.time=dis[mmap[now][i].num];
				q.push(midmid);
			}
		}
	}
	return dis[n]<=ttime;
}
int   main()
{
	long long int  t;
	scanf("%lld",&t);
	while(t--)
	{
		for(long long int  i=0;i<11111;i++)
		{
			mmap[i].clear();
		}
		long long int  l=99999999,r=0;
		scanf("%lld%lld%lld",&n,&m,&ttime);
		for(long long int  i=0;i<m;i++)
		{
			long long int  mid1,mid2,mid3,mid4;
			scanf("%lld%lld%lld%lld",&mid1,&mid2,&mid3,&mid4);
			xjy mid;
			mid.num=mid2;
			mid.time=mid4;
			mid.val=mid3;
			mmap[mid1].push_back(mid);
			mid.num=mid1;
			mmap[mid2].push_back(mid);
			r=max(r,mid.val);
			l=min(l,mid.val);
		}
		long long int  ans=0;
		while(l<=r)
		{
			long long int  mid=(l+r)>>1;
			if(djkstra(mid))
			{
				ans=mid;
				l=mid+1;
			}
			else
				r=mid-1;
		}
		printf("%lld\n", ans);
	}
}  





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值