poj1273--Drainage Ditches(最大流)
来源:互联网 发布:剑三少林正太脸型数据 编辑:程序博客网 时间:2024/06/05 00:29
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 56084 Accepted: 21547
Description
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Input
The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
Output
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
Sample Input
5 41 2 401 4 202 4 202 3 303 4 10
Sample Output
50
直接建图,模板
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;#define maxn 500#define INF 0x3f3f3f3fstruct edge{ int v , w ; int next ;} p[maxn];int head[maxn] , cnt , pre[maxn] , vis[maxn] ;queue <int> q ;void add(int u,int v,int w){ p[cnt].v = v ; p[cnt].w = w ; p[cnt].next = head[u] ; head[u] = cnt++ ; p[cnt].v = u ; p[cnt].w = 0 ; p[cnt].next = head[v] ; head[v] = cnt++ ;}int bfs(int s,int t){ int u , v , min1 = INF , i ; memset(vis,0,sizeof(vis)); vis[s] = 1 ; while( !q.empty() ) q.pop() ; q.push(s) ; while( !q.empty() ) { u = q.front(); q.pop() ; for(i = head[u] ; i != -1 ; i = p[i].next) { v = p[i].v ; if( !vis[v] && p[i].w ) { vis[v] = 1 ; min1 = min(min1,p[i].w) ; pre[v] = i ; q.push(v) ; } } } if( vis[t] ) return min1 ; return -1 ;}int main(){ int n , m , u , v , w , max_flow , i; while(scanf("%d %d", &m, &n)!=EOF) { cnt = 0 ;max_flow = 0 ; memset(head,-1,sizeof(head)); while(m--) { scanf("%d %d %d", &u, &v, &w); add(u,v,w); } memset(pre,-1,sizeof(pre)) ; while(1) { int k = bfs(1,n); if(k == -1) break; max_flow += k ; for(i = pre[n] ; i != -1 ; i = pre[ p[i^1].v ]) { p[i].w -= k ; p[i^1].w += k ; } } printf("%d\n", max_flow); } return 0;}
0 0
- poj1273--Drainage Ditches(最大流)
- poj1273 Drainage Ditches(最大流)
- POJ1273 Drainage Ditches(最大流)
- poj1273 Drainage Ditches (最大流模板)
- POJ1273--Drainage Ditches(最大流)
- POJ1273 Drainage Ditches(最大流)
- POJ1273 Drainage Ditches 【最大流】
- POJ1273 Drainage Ditches(裸最大流,EK,DINIC)
- HDU 1532||POJ1273:Drainage Ditches(最大流)
- POJ1273 Drainage Ditches 最大流模板题(dinic)
- POJ1273 Drainage Ditches (最大流+入门题)
- (POJ1273)Drainage Ditches(裸最大流,EK模板)
- poj1273 Drainage Ditches(最大流EKarp+Dinic+模板总结)
- POJ1273——Drainage Ditches(最大流模板题)
- POJ1273 Drainage Ditches——最大流
- 网络最大流问题 poj1273 Drainage Ditches
- POJ1273 Drainage Ditches最大流模板
- poj1273 Drainage Ditches 最大流EK
- C++设计模式-Bridge桥接模式
- 徐小平:初创团队 合伙人比商业模式更重要
- golang Socket编程
- poj 3734 矩阵快速幂、母函数
- Ubuntu基本安全常识
- poj1273--Drainage Ditches(最大流)
- 程序员如何用8小时之外赚钱?
- 全面剖析网络爬虫
- 分享:进化版动漫更新提醒(微信及软件)
- Lucene 范例
- 大家想知道精神病鉴定有哪些方法吗
- wikioi3287汽车运输 MST+LCA
- stm32 总结
- 黑马程序员----NSSet类型 以及与NSArray区别