POJ1273 Drainage Ditches(最大流)
来源:互联网 发布:电脑淘宝详情页打不开 编辑:程序博客网 时间:2024/05/16 08:34
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
参考Kuangbin大神的,发现他和别人写的不一样的一点就是每次调整都在原图上直接调整,而很多人都是又开了一个可改进量的数组,说不上哪种更好,看个人喜好吧。
#include<iostream>#include<queue>#include<cstring>#include<cstdio>#include<algorithm>const int INF=0x3f3f3f3f;using namespace std;int n,m,map[205][205],path[205],flow[205],start,end;queue<int> q;int bfs(){while(!q.empty())q.pop();memset(path,-1,sizeof(path));path[start]=0;flow[start]=INF;q.push(start);while(!q.empty()){int now=q.front();q.pop();if(now==end)break;for(int i=1;i<=m;i++){if(i!=start&&path[i]==-1&&map[now][i]){flow[i]=min(flow[now],map[now][i]);q.push(i);path[i]=now;}}}if(path[end]==-1)return -1;return flow[end];}int Edmonds_Karp(){int MaxFlow=0,step,now,pre;while(bfs()!=-1){step=bfs();MaxFlow+=step;now=end;while(now!=start){pre=path[now];map[pre][now]-=step;map[now][pre]+=step;now=pre;}}return MaxFlow;}int main(void){while(~scanf("%d%d",&n,&m)){memset(map,0,sizeof(map));for(int i=0;i<n;i++){int u,v,w;scanf("%d%d%d",&u,&v,&w);map[u][v]+=w;}start=1;end=m;printf("%d\n",Edmonds_Karp());}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
- VMware 中很多ATA ChannelX 问题解决方法
- jsonp处理方法
- LeetCode 172 Factorial Trailing Zeroes(阶乘后的零)(*)
- 面试题总结 持续更新ing……
- eclipse安装activiti插件和基本使用
- POJ1273 Drainage Ditches(最大流)
- Mysql的游标的定义使用及关闭深入分析
- 论文总结
- POJ 1753(DFS+枚举||BFS+位运算)
- iOS如何实现购物车物品的选中以及加减 tableView
- hdu 1031 最小生成树
- 【罗塞塔石碑】—My Lover(Two.iso)
- 安卓中dialog从地上弹出来效果。
- Go语言入门(一)——接口的实现