hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
来源:互联网 发布:广东榕泰怎么有云计算 编辑:程序博客网 时间:2024/05/21 22:57
有N个点,点1为珍贵矿物的采矿区, 点N为加工厂,有M条双向连通的边连接这些点。走每条边的运输容量为C,运送时间为D。选择一条从1到N的路径运输, 这条路径的运输总时间要在T之内,在这个前提之下,要让这条路径的运输容量尽可能地大。一条路径的运输容量取决与这条路径中的运输容量最小的那条边。
带限制的最短路---
由于每条路都是有一定容量的,相对来说,容量越大那么满足的边就越少。就可以二分容量来求出满足的最大容量了。
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;const int N = 100005;const int inf = 1 << 28;struct node{ int to, nxt, cost, cap;}e[N*5];int head[N], dis[N], vis[N];int cap[N];int cnt;int n, m, t;int limt;void init(){ cnt = 0; memset(head, -1, sizeof(head));}bool cmp(int a, int b){ return a > b;}void add( int u, int v, int cap, int cost ){ e[cnt].to = v; e[cnt].cap = cap; e[cnt].cost = cost; e[cnt].nxt = head[u]; head[u] = cnt++; e[cnt].to = u; e[cnt].cap = cap; e[cnt].cost = cost; e[cnt].nxt = head[v]; head[v] = cnt++;}void spfa(){ queue<int> q; while(!q.empty()) q.pop(); memset(vis, 0, sizeof(vis)); for( int i = 1; i <= n; i++ ) dis[i] = inf; dis[1] = 0; vis[1] = 1; q.push(1); while( !q.empty() ) { int now = q.front(); q.pop(); vis[now] = 0; for( int i = head[now]; ~i; i = e[i].nxt ) if(e[i].cap >= limt) { int to = e[i].to; if( dis[to] > dis[now] + e[i].cost ) { dis[to] = dis[now] + e[i].cost; if( !vis[to] ) { vis[to] = 1; q.push(to); } } } }}int main(){ int tot; for( scanf("%d", &tot); tot--; ) { scanf("%d%d%d", &n, &m, &t); init(); int u, v, cp, tt; for( int i = 1; i <= m; i++ ) { scanf("%d%d%d%d", &u, &v, &cp, &tt); cap[i] = cp; add(u, v, cp, tt); } sort(cap+1, cap+1+m, cmp); int l = 1, r = m; while(l < r) { int mid = (l + r) >> 1; limt = cap[mid]; spfa(); if( dis[n] == inf || dis[n] > t ) l = mid + 1; else r = mid; } printf("%d\n", cap[l]); } return 0;}
0 0
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- hdu 1839 Delay Constrained Maximum Capacity Path【二分+SPFA】
- hdu 1839 Delay 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 (二分最短路)
- 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
- iOS如何给图片加缓存
- 单片机小白学步系列(二十二) IO口:蜂鸣器的使用/三极管的工作原理
- C 语言程序设计实践 3.7 Judge
- USB 基本知识
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- Codeforces Round #157 (Div. 2)D(数位DP+组合数)
- MongoDB基本使用
- Browser首页为一张图片
- 单片机小白学步系列(二十三) IO口原理知识补充:双向IO口、互补推挽、高阻态
- C 语言程序设计实践 3.8 Volume
- USB的工作原理
- sdfg
- windows live writer