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. Delphi中取得程序版本号

    Delphi做的程序,如果想包含版本信息, 必须在Delphi的集成编辑环境的菜单“Project/Options/Version Info”里面添加版本信息.即在Version Info 选项卡中选 ...

  2. JAVA多线程及补充

    进程 运行中的应用程序叫进程,每个进程运行时,都有自已的地址空间(内存空间)如IE浏览器在任务管器中可以看到操作系统都是支持多进程的 线程 线程是轻量级的进程,是进程中一个负责程序执行的控制单元线程没 ...

  3. 将CRUD封装到一个工具类中

    package org.zln.hibernate.utils; import org.hibernate.Session; import org.hibernate.SessionFactory; ...

  4. ASP.NET页面之间传值Server.Transfer(4)

    这个才可以说是面象对象开发所使用的方法,其使用Server.Transfer方法把流程从当前页面引导到另一个页面中,新的页面使用前一个页面的应答流,所以这个方法是完全面象对象的,简洁有效. Serve ...

  5. Hibernate查询语言——HQL

    HQL(Hibernate Query Language)查询语言是完全面向对象的查询语言,它提供了更加面向对象的封装,可以理解如多态.继承和关联. HQL的基本语法如下: select " ...

  6. Codeforces Round #268 (Div. 1) 468D Tree(杜教题+树的重心+线段树+set)

    题目大意 给出一棵树,边上有权值,要求给出一个1到n的排列p,使得sigma d(i, pi)最大,且p的字典序尽量小. d(u, v)为树上两点u和v的距离 题解:一开始没看出来p需要每个数都不同, ...

  7. IE提示是否只查看安全传送的网页内容

    IE选项-->安全-->点上面那个地球internet-->点下面那个 自定义级别-->找到“其他”-->显示混合内容,改为启用,重启打开下IE,就可以了

  8. 12.25模拟赛T1

    可以区间dp,但是复杂度太高. 所以应该是贪心,怎么贪心呢? 这种题目,最好还是手玩找一些规律. 可以发现,由于保证可以m次填完,所以颜色之间没有相互包含关系. 比较像分治的模型. 所以考虑拿到一个区 ...

  9. Cube 找规律

    这道题我们经过简单的推测便可得知3个之前特判,四个之后就成为了一般状况,就是我们每侧都是走整个整个的|_|之后零的走|||. 考试的时候包括平时做题,许多正确的感性比理性证明要强得多. #includ ...

  10. es6+最佳入门实践(6)

    6.Symbol用法 6.1.什么是Symbol? Symbol是es6中一种新增加的数据类型,它表示独一无二的值.es5中我们把数据类型分为基本数据类型(字符串.数字.布尔.undefined.nu ...