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. CodeForces 697B Barnicle 模拟

    强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...

  2. eclipse启动Heritrix

    首先下载heritrix-1.14.4-src源码.可以在http://sourceforge.net/projects/archive-crawler/files/archive-crawler ( ...

  3. python 进制 转换

    测试用的python源码 ''''' Created on 2014年8月21日 @author: lenovo ''' import binascii import struct def examp ...

  4. Entity Framework 6.x Code First 基础

    安装扩展工具 "Entity Framework Power Tools Beta4" 可选, 主要用于数据库变结构反向生成C#的对象和对应的mapping类.如果你熟悉mappi ...

  5. Confluence搭建

    参见 https://confluence.atlassian.com/display/CONF54/Installing+the+Confluence+EAR-WAR+Edition 下载5.4.4 ...

  6. Python 常见的内置模块

    datetime datetime是python处理日期和时间的标准库 获取当前日期和时间 我们先看看如何获取当前的日期和时间: >>> from datetime import d ...

  7. hive深入

    Hive QL: Create Table 创建一个指定名字的表.如果相同名字的表已经存在,则抛出异常:用户可以用 IF NOT EXIST 选项来忽略这个异常. EXTERNAL 关键字可以让用户创 ...

  8. 711B - Chris and Magic Square 模拟

    题目大意:在num[i][j]==0处填一个数使每行,每列,对角线的和相同,若果有多种答案输出一种. 题目思路:模拟 #include<iostream> #include<algo ...

  9. 正则表达式判断ip地址

    html: <div class="configuration"><form action="" name="myformcon&q ...

  10. 11--Python 备份文件程序

    最近看了下<A Byte of Python>, 看见一个非常有意思的程序,用python进行文件行备份的练习程序, 自己在机器上敲代码运行了一遍,结果出现了一个小问题,路径出错--&qu ...