HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
来源:互联网 发布:win7共享输入网络凭据 编辑:程序博客网 时间:2024/05/16 10:11
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1514 Accepted Submission(s): 480
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
22 1 101 2 13 104 4 201 2 1000 152 4 999 61 3 100 153 4 99 4
Sample Output
1399
Author
Mugurel Ionut Andreica
题目大意:给出n个点,m条路,以及每条路的端点,容纳量,通过时间,问T时间内可以通过的最大容量
其实一开始看题时以为在TH迪的引导下以为是最大流,还好坚持了自我,一直坚定的按照最短路做,其实正解也是最短路SPFA 算法,敲一个标准的版+判断一下点的容纳值就好了,二分的做法着实没想到,代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <map>#include <list>#include <cmath>#include <queue>#include <stack>#include <set>#include <algorithm>#define LL long long#define INF 0x3f3f3f3f#define RR freopen("in.txt","r",stdin)#define WW freopen("out.txt","w",stdout)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const int N = 10010;const int M = 500010;struct node{ int v,w,t; int next;} edge[M*2];int head[M];bool vis[N];int cnt;int d[N];int Cap[M];int n,m,T;bool cmp(int a,int b){ return a > b;}void SPFA(int Val){ queue<int >Q; memset(vis,false,sizeof(vis)); memset(d, INF, sizeof(d)); Q.push(1); d[1] = 0; while(!Q.empty()) { int u = Q.front(); Q.pop(); vis[u] = false; for(int i = head[u]; i != -1; i= edge[i].next) { int v = edge[i].v; int w = edge[i].w; int t = edge[i].t; if(Val <= w) { if(d[v] > d[u] + t) { d[v] = d[u] + t; if(!vis[v]) { vis[v] = true; Q.push(v); } } } } }}void Add(int u,int v,int w,int t){ edge[cnt].v = v; edge[cnt].w = w; edge[cnt].t = t; edge[cnt].next = head[u]; head[u] = cnt++;}void Solve(int l,int r){ if(l >= r) { printf("%d\n",Cap[l]); return ; } int mid = (l + r) >> 1; SPFA(Cap[mid]); if(d[n] == INF || d[n] > T) Solve(mid+1, r); else Solve(l,mid);}int main(){ int X; scanf("%d",&X); while(X--) { cnt = 0; scanf("%d%d%d",&n,&m,&T); memset(head, -1, sizeof(head)); for(int i=0; i<m; i++) { int u,v,w,t; scanf("%d%d%d%d",&u,&v,&w,&t); Add(u,v,w,t); Add(v,u,w,t); Cap[i] = w; } sort(Cap,Cap+m,cmp); Solve(0, m-1); } return 0;}
0 0
- 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 (二分最短路)
- 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 二分下限+最短路spfa
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分搜索)
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu 1839 Delay Constrained Maximum Capacity Path【二分+SPFA】
- 南大软院大神养成计划--第十三天网页细节处理中
- 工业4.0时代袭来
- 就Share来谈谈一些小看法
- STM32学习第五天---看了CT117E比赛版的硬件结构
- 《Android开发艺术探索》笔记之Activity的生命周期和启动模式
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
- CodeForces 161D Distance in Tree 树形DP
- 指针和数组的区别
- 最不能勉强的,莫过于感情
- 工作感悟-后续篇
- javascript权威指南学习笔记(一)
- NAT模式 虚拟主机与宿主网段不同
- MDK5(Keil for ARM) 工程建立时遇到的问题集锦
- Android可收缩/扩展的TextView【2】