Drainage Ditches

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm> using namespace std;
const int inf=0x7fffffff;
int vis[],pre[],mp[][];
int i,n,m,sum;
long long ans;
int bfs()
{
int findpath=;
queue<int> Q;
memset(vis,,sizeof(vis));
memset(pre,,sizeof(pre));
pre[]=;
vis[]=;
Q.push();
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for(int i=;i<=n;i++)
if(mp[u][i]> && !vis[i])
{
vis[i]=;
pre[i]=u;
Q.push(i);
if (i==n) {findpath=; break;}
}
}
if (!findpath) return ;
int maxflow=inf;
int v=n;
while(pre[v]>)
{
maxflow=min(maxflow,mp[pre[v]][v]);
v=pre[v];
}
v=n;
while(pre[v]>)
{
mp[v][pre[v]]+=maxflow;
mp[pre[v]][v]-=maxflow;
v=pre[v];
}
return maxflow;
}
int main()
{
while(~scanf("%d%d",&m,&n))
{
memset(mp,,sizeof(mp));
for(i=;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
mp[x][y]+=z;//找了好久的错误,最后发现可能有好多条重复的,要累加
}
ans=;
while(sum=bfs()) ans+=sum;
printf("%d\n",ans);
}
return ;
}

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

  1. HDU 1532 Drainage Ditches (网络流)

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

  2. HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏

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

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

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

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

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

  5. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

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

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

  7. hdu 1532 Drainage Ditches(网络流)

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

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

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

  9. hdoj 1532 Drainage Ditches(最大网络流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用Edmonds ...

随机推荐

  1. Chapter 15_1 require函数

    Lua提供了一个名为require的高层函数来加载模块,但这个函数只假设了关于模块的基本概念. 对于require而言,一个模块就是一段定义了一些值(函数或者包含函数的table)的代码. 为了加载一 ...

  2. 第1章 初识java----输出多行的语句写法

    public class onesixtwo{ public static void main(String[] args){ System.out.println("----------- ...

  3. InnoDB表要建议用自增列做主键

    InnoDB引擎表是基于B+树的索引组织表(IOT): 每个表都需要有一个聚集索引(clustered index): 所有的行记录都存储在B+树的叶子节点(leaf pages of the tre ...

  4. 关于个人网站选择虚拟主机还是VPS服务器的讨论

    还记得当初才开始学习建站的时候,选择的第一款虚拟主机是全HTML的主机,那时候的虚拟主机还分为HTML或者是ASP,PHP的都很少,在国内接触的学习较多还是以ASP为主,PHP是最近几年才开始流行.如 ...

  5. VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法

    问题 : 在用VS2008写一段代码,算法都没有问题,但是调试的时候发现出了main之后就报 Stack around the variable 'xxx' was corrupted 的错误,后来发 ...

  6. hdu_5274_Dylans loves tree(树剖)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5274 题意:给一棵树和叶子的值,然后有单点修改操作和询问区间操作,询问的是每一个值出现的奇偶次数,如果 ...

  7. 利用DataImportHandler建索引时一直无法完成

    问题研究 项目中需要利用DataImportHandler从hive中sync数据到solr.发现有时候hive sql已经执行完几个小时了,sync任务还没有完成,貌似哪里卡住了.重启solr后重新 ...

  8. echo json数据给ajax后, 需要加上exit,防止往下执行,带上其他数据,到时ajax失败

    01返回json数据给ajax后需要加上exit.返回json数据前不能有其他输出 function apply(){ if(IS_POST){$info['status'] = 1; echo js ...

  9. 第3章 Java语言基础----成员变量与局部变量

    在对局部变量进行赋值时,不能对非静态字段age进行静态引用,图1错误,加上static后图二正确,图3与图4类似,如下图所示: 图1图2 图3图4 2.成员变量times在类中定义,局部变量times ...

  10. flash检测网络是否通畅

    air: 要在 Adobe ® Flash ® Professional(CS4 或更高版本)中使用 air.net 包: 选择“文件”>“发布设置”命令. 在 Flash 面板中,单击 Act ...