HDU1532 Drainage Ditches(网络流模板)
来源:互联网 发布:java中import的用法 编辑:程序博客网 时间:2024/05/21 16:58
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9077 Accepted Submission(s): 4261
Problem 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
很简单的求最大流的问题==,看代码注释
//http://acm.hdu.edu.cn/showproblem.php?pid=1532#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define mmax 220#define INF 0x7fffffffusing namespace std;int cap[mmax][mmax]; //限制容量int f[mmax][mmax]; //当前容量int p[mmax];int next[mmax]; //记录父节点int n,m;int maxflow(int s,int t){ int flow=0; memset(f,0,sizeof(f)); while(1) { queue <int>qu; memset(p,0,sizeof(p)); p[s]=INF; //将源点赋为无穷大 qu.push(s); while(!qu.empty()) //在残量网络中找到一条增广路 { int out = qu.front(); qu.pop(); if(out==t) break; for(int i=1;i<=m;i++) { if(!p[i] && f[out][i] < cap[out][i]) //找到新节点,保证该节点的流量小于限制流量和初次被访问 { next[i]=out; //记住父节点, p[i]= p[out] < cap[out][i]-f[out][i]? p[out]:cap[out][i]-f[out][i]; //找该增广路中的最小残留量 qu.push(i); } } } if(!p[t]) //如果到不了汇点t,那么跳出循环,不再继续寻找增广路 break; for(int i=t;i!=s;i=next[i])//从汇点开始逆向更新流量 { f[i][next[i]] -= p[t]; //更新反向流量 f[next[i]][i] += p[t]; //更新正向流量 } flow+=p[t]; } return flow;}int main(){ while(scanf("%d %d",&n,&m)!=EOF) { int a,b,c; memset(cap,0,sizeof(cap)); for(int i =1 ; i <= n ; i++) { scanf("%d %d %d",&a,&b,&c); cap[a][b] += c; //为了防止重边,这里使用+= } printf("%d\n",maxflow(1,m)); } return 0;}
0 0
- HDU1532 Drainage Ditches(网络流模板)
- HDU1532 Drainage Ditches 网络流模板
- HDU1532 - Drainage Ditches(网络流)
- hdu1532——Drainage Ditches(网络流模板)
- HDU1532 Drainage Ditches 最大流Dinic模板
- Drainage Ditches(HDU1532,网络流)
- HDU1532 Drainage Ditches(网络流EdmondsKarp)
- HDU1532 Drainage Ditches(网络流、EdmondsKarp)
- hdu1532 Drainage Ditches (网络流入门)&(EK算法模板)
- HDU1532 Drainage Ditches 最大流
- HDU1532 Drainage Ditches 【最大流】
- HDU1532 - Drainage Ditches 网络流之最大流
- HDU1532 Drainage Ditches (网络流基础水题)
- 增广路算法(网络流) HDU1532 Drainage Ditches
- HDU1532——Drainage Ditches(网络流Dinic算法)
- HDU1532 Drainage Ditches 网络流之SAP算法
- hdu1532 Drainage Ditches (网络流入门)
- HDU1532 Drainage Ditches【最大流】【Edmond-Karp】
- java构造方法与方法的区别
- cocos2d-x-3.2alpha0 如何创建新工程
- vc6 两个问题记录
- JavaFX文档(12)掌握FXML——4使用FXML来创建自定义控件
- 考研机试真题(一)之排序
- HDU1532 Drainage Ditches(网络流模板)
- Fedora GNOME3提示出现错误无法恢复
- lightoj 1224
- notepad++ 插件
- 逆向学习法
- mapreduce编程(二)- 大象书中求每一年的最高温度
- OpenStack是下一拨的技术潮流吗?
- 液晶显示器像素时钟信号DCLK
- oracle 分页查询