Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22789    Accepted Submission(s): 10905

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. 
 
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 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
 
Sample Output
50
 
Source
 
 
 
 
代码:
 #include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=+;
int flow[N][N];
int mark[N],pre[N];
int n,m,f;
void max_flow(){
while(){
memset(mark,,sizeof(mark));
memset(pre,,sizeof(pre));
queue<int>Q;
mark[]=;
Q.push();
while(!Q.empty()){
int cnt=Q.front();
Q.pop();
if(cnt==n)break;
for(int i=;i<=n;i++){
if(!mark[i]&&flow[cnt][i]>){
mark[i]=;
Q.push(i);
pre[i]=cnt;
}
}
}if(!mark[n])break;
int minx=INF;
for(int i=n;i!=;i=pre[i]){
minx=min(flow[pre[i]][i],minx);
}
for(int i=n;i!=;i=pre[i]){
flow[pre[i]][i]-=minx;
flow[i][pre[i]]+=minx;
}
f+=minx;
}
}
int main(){
while(~scanf("%d%d",&m,&n)){
memset(flow,,sizeof(flow));
for(int i=;i<m;i++){
int u,v,len;
scanf("%d%d%d",&u,&v,&len);
flow[u][v]+=len;
}
f=;
max_flow();
printf("%d\n",f);
}
return ;
}

HDU 1532.Drainage Ditches-网络流最大流的更多相关文章

  1. poj 1273 && hdu 1532 Drainage Ditches (网络最大流)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53640   Accepted: 2044 ...

  2. hdu 1532 Drainage Ditches(最大流模板题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu 1532 Drainage Ditches(网络流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 题目大意是:农夫约翰要把多个小池塘的水通过池塘间连接的水渠排出去,从池塘1到池塘M最多可以排多少 ...

  4. 【初识——最大流】 hdu 1532 Drainage Ditches(最大流) USACO 93

    最大流首次体验感受—— 什么是最大流呢? 从一个出发点(源点),走到一个目标点(汇点),途中可以经过若干条路,每条路有一个权值,表示这条路可以通过的最大流量. 最大流就是从源点到汇点,可以通过的最大流 ...

  5. HDU 1532 Drainage Ditches(网络流模板题)

    题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...

  6. HDU 1532 Drainage Ditches(最大流 EK算法)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...

  7. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

  9. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

  10. HDU 1532 Drainage Ditches (最大网络流)

    Drainage Ditches Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) To ...

随机推荐

  1. hibernate笔记(三)

    目标: 第1部分: 对象的状态: 第2部分:缓存 1) 一级缓存 2) 相关知识 ----懒加载--- 第3部分:映射 一对一映射 组件映射 继承映射 一.对象的状态 举例: User   user  ...

  2. BZOJ4423 AMPPZ2013Bytehattan(并查集)

    判断网格图中某两点是否被割开,可以将割边视为边区域视为点,转化为可切割这两点的区域是否连通.于是每次判断使两个区域连通后是否会形成环(边界视为连通),若是则说明被两点被割开.并查集维护. #inclu ...

  3. POJ 开关问题 解题报告

    开关问题 Time Limit: 1000MS Memory Limit: 30000K Description 有N个相同的开关,每个开关都与某些开关有着联系,每当你打开或者关闭某个开关的时候,其他 ...

  4. 【BZOJ 3376】[Usaco2004 Open]Cube Stacking 方块游戏 带权并查集

    这道题一开始以为是平衡树结果发现复杂度过不去,然后发现我们一直合并而且只是记录到最低的距离,那么就是带权并查集了,带权并查集的权一般是到根的距离,因为不算根要好打,不过还有一些其他的,具体的具体打. ...

  5. Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition

    C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...

  6. Good Substrings CodeForces - 271D

    You've got string s, consisting of small English letters. Some of the English letters are good, the ...

  7. 最小k度最小生成树模板

    代码是抄的 题解是瞄的 可我想学习的心是真的嘤嘤嘤 然而 还是上传一份ioi大神的论文吧 链接:https://pan.baidu.com/s/1neIW9QeZEa0hXsUqJTjmeQ 密码:b ...

  8. apply()和call()

    每个函数都包含俩个非继承而来的方法:apply() 和 call(),这俩个方法的用途都是在特定的作用域中调用函数,实际上等于设置函数体内this对象的值,以扩充函数赖以运行的作用域.一般来讲,thi ...

  9. centos配置数据源和java环境配置

    ---恢复内容开始--- 一:前言 今天送走了一位同事,看着别人走勾起了我蠢蠢欲动的心啊,但是我知道,我不能那么的任性,我是men,这几天难得的清闲,所以我就弄一弄linux,昨天把网给配通了,今天配 ...

  10. 【BZOJ】1691: [Usaco2007 Dec]挑剔的美食家

    [算法]扫描线+平衡树(set) [题解]很明显的二维偏序数点,排序后扫描线,现加点后查询答案. 则问题转化为一维偏序,显然贪心找第一个比当前大的最优,所以用平衡树维护. 记得开multiset!!! ...