poj Drainage Ditches 1273 (最大流入门)
来源:互联网 发布:郑州网络推广哪家专业 编辑:程序博客网 时间:2024/05/16 10:31
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 64026 Accepted: 24713
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
题意:(最大流模板)
有n个城市,n条路,出发点在1,终点在m,让求最大流。
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>#define INF 0x3f3f3f3f#define N 220using namespace std;int p[N];bool vis[N];int map[N][N];int s,e;int n,m;bool bfs(){queue<int>q;memset(p,0,sizeof(p));memset(vis,false,sizeof(vis));vis[s]=1;q.push(s);while(!q.empty()){int ss=q.front();q.pop();if(ss==e)return true;//如果找到一条从1到n的路。 for(int i=2;i<=n;i++){if(!vis[i]&&map[ss][i])//如果可到达,但还没访问,遍历所有与i相连的城市 {q.push(i);p[i]=ss;//p[]数组里存放父节点 vis[i]=1;}}}return false;//找不到 }int maxflow(){int ans=0;//记录最大流 while(1){if(!bfs())//如果没有从1到n的路 return ans;//直接输出流量 int mm=INF;for(int i=e;i!=s;i=p[i])//从终点往起点找(从最小子孙往祖宗找) mm=min(mm,map[p[i]][i]);//找到关系网中的最小的残留量。 for(int i=e;i!=s;i=p[i])//逐个更新 {map[p[i]][i]-=mm;//正着的(父到子) map[i][p[i]]+=mm;//反着的(子到父) }ans+=mm;//更新最大流 }}int main(){int u,v,w;while(scanf("%d%d",&m,&n)!=EOF){s=1;e=n;memset(map,0,sizeof(map));while(m--){scanf("%d%d%d",&u,&v,&w);map[u][v]+=w;//每条边赋初值 }printf("%d\n",maxflow());}return 0;}
0 0
- POJ 1273 Drainage Ditches(最大流入门)
- POJ 1273 Drainage Ditches(最大流入门)
- poj Drainage Ditches 1273 (最大流入门)
- POJ 1273 Drainage Ditches (最大流入门~)
- POJ-1273 Drainage Ditches(最大流入门)
- POJ-Drainage Ditches-最大流入门题
- POJ 1273 Drainage Ditches(最大流入门题)
- POJ 1273 || HDU 1532 Drainage Ditches ,最大流入门题
- POJ 1273 Drainage Ditches 最大流入门题
- poj 1273 Drainage Ditches 【最大流入门 dinic算法】
- poj 1273 Drainage Ditches(网络流入门之最大流)
- Poj 1273 Drainage Ditches【最大流入门题----Ford-Fulkerson】
- poj1273 Drainage Ditches(最大流入门)
- POJ - 1273 Drainage Ditches (网络流入门题)
- POJ 1273 Drainage Ditches(网络流入门)
- NYOJ 323 && HDU 1532 && POJ 1273 Drainage Ditches (网络流之最大流入门)
- poj 1273 Drainage Ditches 网络流最大流入门 ford-fulkerson
- [POJ 1273]Drainage Ditches——网络流最大流入门
- bash语言学习
- 黑马程序员-----三、Android开发日常积累之-----安卓网络传输文本数据格式(json)
- 黑马程序员---递归小结
- hdu 2578 Dating with girls(1)
- void *空(无)类型指针
- poj Drainage Ditches 1273 (最大流入门)
- smab的配置
- CSS布局模型
- C++字符串3——存取赋值
- 文章标题
- 史上最详尽的git图文教程,包学包会
- 伪分布式Hadoop安装
- Eclipse搜索文件名,以及搜索文件中特定的内容
- hdoj 2054 A == B ?【大数判断题】