链接:
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): 226 Accepted Submission(s): 98
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
题目大意:
有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。
他们要选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。
一条路径的运输容量取决与这条路径中的运输容量最小的那条边。
分析与总结:
因为每条路径的容量取决于这条路径中所有边中的最小容量,所以我们可以以此枚举最小容量。
但是如果一个一个容量的枚举,那明显效率太低了。
通过分析,可以看出,如果最低容量越大,那么符合要求的路径就越少,所以,根据容量的大小,路径数量是单调的。
有了单调性,就可以利用二分法了。
只要把容量从大到小进行排序,然后二分之,很快便能算出答案。
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int INF = 0x7fffffff; const int VN = 10005; const int EN = 50005; struct Edge{int v,next,cap,time;}E[EN*2]; int n, m, t; int size; int head[VN]; int cap[EN]; int d[VN]; int Time[VN]; int limit; bool inq[VN]; void init(){ size=0; memset(head, -1, sizeof(head)); } void addEdge(int u,int v,int c,int d){ E[size].v=v; E[size].cap=c; E[size].time=d; E[size].next = head[u]; head[u] = size++; } int Dijkstra(int src){ memset(inq, 0, sizeof(inq)); for(int i=1; i<=n; ++i)d[i]=INF; d[src] = 0; queue<int>q; q.push(src); while(!q.empty()){ int u = q.front(); q.pop(); inq[u] = false; for(int e=head[u]; e!=-1; e=E[e].next)if(E[e].cap>=limit){ int tmp = d[u]+E[e].time; if(d[E[e].v] > tmp){ d[E[e].v] = tmp; if(!inq[E[e].v]){ inq[E[e].v] = true; q.push(E[e].v); } } } } return d[n]; } int main(){ int T, u, v, c, d; scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&m,&t); init(); for(int i=0; i<m; ++i){ scanf("%d%d%d%d",&u,&v,&c,&d); cap[i]=c; addEdge(u,v,c,d); addEdge(v,u,c,d); } sort(cap, cap+m,greater<int>()); // 二分求解 int left=0, right=m-1, mid; while(left<right){ mid = (left+right)>>1; limit = cap[mid]; int tmp=Dijkstra(1); if(tmp==INF || tmp>t){ left = mid+1; } else{ right=mid; } } printf("%d\n", cap[left]); } return 0; }
更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索time
, to
, Factory
, of
The
maximum capacity、maximum ap capacity、constrained、constrained true、be constrained to,以便于您获取更多的相关知识。