复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)
来源:互联网 发布:菜鸟网络物流公司官网 编辑:程序博客网 时间:2024/06/15 08:54
Delay Constrained Maximum Capacity Path
Time Limit:10000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64uDescription
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
22 1 101 2 13 104 4 201 2 1000 152 4 999 61 3 100 153 4 99 4
Sample Output
1399
由1点到n点的通过量取决于在这条路上的最小的路的容量,这样按最终通过量来进行二分,枚举可能出现的通过量,计算最短时间,如果时间小于或等于最大时间t,将通过量上调,直到最短时间大于t,这样最后一次通过的 就是最大通过量。使用SPFA来简化计算量
原理:随着通过量的增加,会使可以使用的边变少,总会使求出的最短时间不变或是增加,这样就得到了通过量于最短时间的线性关系。最终只要最短时间不超过t就可以让通过量增加。
#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;struct node{ int x , y , v , w ; node *next ;} *head[20000];void add(int x,int y,int v,int w){ node *q = new node ; q->x = x ; q->y = y ; q->v = v ; q->w = w ; q->next = head[x] ; head[x] = q ;}int dis[20000] , vis[20000] ;queue <int> Q ;int spfa(int n,int mid){ memset(dis,INF,sizeof(dis)); memset(vis,0,sizeof(vis)); while( !Q.empty() ) Q.pop() ; dis[1] = 0 ; vis[1] = 1 ; Q.push(1); while( !Q.empty() ) { int x = Q.front() , y , v ; Q.pop() ; vis[x] = 0 ; for( node *q = head[x] ; q != NULL ; q = q->next ) { x = q->x ; y = q->y ; v = q->v ; if( v >= mid && dis[y] > dis[x] + q->w ) { dis[y] = dis[x] + q->w ; if( !vis[y] ) { vis[y] = 1; Q.push(y) ; } } } } return dis[n] ;}int main(){ int t , i , j , n , m , time ; node *q ; scanf("%d", &t); while(t--) { memset(head,NULL,sizeof(head)); scanf("%d %d %d", &n, &m, &time); int x , y , v , w , low = INF , top = 0 ; for(i = 0 ; i < m ; i++) { scanf("%d %d %d %d", &x, &y, &v, &w); add(x,y,v,w); add(y,x,v,w); low = min(low,v); top = max(top,v); } int mid , ans ; while(low <= top) { mid = (low + top)/2; if( spfa(n,mid) <= time ) { ans = mid ; low = mid + 1; } else top = mid - 1 ; } printf("%d\n", ans); } return 0;}
0 0
- 复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu1839—Delay Constrained Maximum Capacity Path(spfa+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- HDU1839---Delay Constrained Maximum Capacity Path(SPFA+vector+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path【二分+SPFA】
- hdu1839Delay Constrained Maximum Capacity Path(二分 + spfa)
- HDU1839Delay Constrained Maximum Capacity Path(二分答案+SPFA)经典
- hdu 1839 Delay Constrained Maximum Capacity Path 二分下限+最短路spfa
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- 【HDU】1839 Delay Constrained Maximum Capacity Path 二分+最短路
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+最短路
- HDU 1839 Delay Constrained Maximum Capacity Path (二分最短路)
- 如何使得CTreeCtrl 失去焦点后,选中项的颜色仍然保持不变,怎么实现?高亮
- leetcode总结无止境系列之链表
- Dual Palindromes 双重回文数
- 通过jQuery源码学习javascript(三)
- MacTex写中文
- 复习图---Delay Constrained Maximum Capacity Path(SPFA+二分)
- DNA生物基因植入阻断术的适用范围
- UVa1646Edge Case
- Civil and Evil Engineer(最小生成树+最大生成树)
- 关于vc6.0出现的“打开文件崩溃”以及“导入工程崩溃”的问题
- LPC1768之串口UART0
- Codeforces 453A. Little Pony and Expected Maximum
- 关于ioremap,request_mem_region
- Javascript学习系列(四)脚本之家