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. Leetcode 136 137 260 SingleNumber I II III

    Leetccode 136 SingleNumber I Given an array of integers, every element appears twice except for one. ...

  2. 安装cocoapods遇到的一些问题

    其实可以直接到https://github.com/CocoaPods/Specs上把所需的文件夹下载下来 解压后命名为master放在本地的 ~/.cocoapods/repos  下面就行 但是使 ...

  3. 基于Centos6.6的R720服务器四网口端口聚合的实践

    服务器多网口端口聚合,其目的主要在于网卡容灾和提升带宽.linux端口绑定,提供7种模式,如下: 关于mode共有0-6等7种模式,详细请参考官方手册!mode的值表示工作模式,他共有0,1,2,3, ...

  4. bootsraps ch1

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  5. SCU 1069 POJ 2955 Brackets

    区间DP #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  6. c语言-经验之谈

    如果你是一个大牛,那就直接忽略这里. 如果你是一个新手,请继续向下看. 在自学计算机的路上真的很悲惨,如果你是在学校里面学习还算比较幸运. 针对编程来说,在学校里面学习的只是学会了语言,而很少有人学会 ...

  7. python常用正则表达式

    匹配特定数字:^[1-9]\d*//匹配正整数−[1−9]\d∗  //匹配负整数^-?[1-9]\d*//匹配整数[1−9]\d∗|0 //匹配非负整数(正整数 + 0)^-[1-9]\d*|0// ...

  8. Entity Framework技巧系列之十四 - Tip 56

    提示56. 使用反射提供程序编写一个OData Service 在TechEd我收到一大堆有关将数据作为OData暴露的问题. 到目前为止你大概知道可以使用数据服务与Entity Framework将 ...

  9. 经典.net面试题目(1)

    1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private :   私有成员, 在类的内部才可以访问. protected : 保 ...

  10. As3.0 视频缓冲、下载总结

    来源:http://www.cuplayer.com/player/PlayerCodeAs/2012/0913404.html 利用NetStream的以下属性: bufferTime — 缓冲区大 ...