HDU 1532 Drainage Ditches (最大网络流)
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
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
Output
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 (最大网络流)的更多相关文章
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- 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) ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- hdu 1532 Drainage Ditches(最大流模板题)
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1532 Drainage Ditches(网络流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 题目大意是:农夫约翰要把多个小池塘的水通过池塘间连接的水渠排出去,从池塘1到池塘M最多可以排多少 ...
- HDU 1532 Drainage Ditches(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- hdoj 1532 Drainage Ditches(最大网络流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用Edmonds ...
随机推荐
- mysql之inner join 和left join/right join
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- CodeForces 697B Barnicle 模拟
强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...
- Asp.Net MVC 在后台获取PartialView、View文件生成的字符串
在Asp.net MVC的实际开发中,有时需要在后台代码中获取某个View 或者 PartialView 生成的字符串,示例如下: 1. 将View文件输出为字符串: /// <summary& ...
- error while loading shared libraries: libseaudit.so.4: cannot open shared object file: Error 40
安装共享库后要注意共享库路径设置问题, 如下: 1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令 ldconfig命令的用途, 主要是在默认搜寻目录( ...
- 利用redis做频率限制第一篇
public Result checkRateLimit(String clientIp, int ipTime, int ipCount) { // 每个ip的redis的key都不一样 Strin ...
- Windows命令查看文件MD5码
D:\>certutil -hashfile md5test.txt MD5 MD5 哈希(文件 md5test.txt): d6 f6 bb 38 b5 6b 67 8f 34 9b e4 d ...
- # Linux Whois3获取 运营商信息
Linux Whois3获取 运营商信息 APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的,并提供了一个查询工具,下面就让我们看看如何在Linux ...
- c语言-键盘扫描码
定义: 键盘上的每一个键都有两个唯一的数值进行标志.为什么要用两个数值而不是一个数值呢?这是因为一个键可以被按下,也可以被释放.当一个键按下时,它们产生一个唯一的数值,当一个键被释放时,它也会产生一个 ...
- spark开发
1. 主要参考资料http://spark.incubator.apache.org/docs/latest/scala-programming-guide.htmlhttp://www.eecs.b ...
- oc知道经纬度求位置
CLLocation *newLocation = [locations lastObject]; CLGeocodeCompletionHandler handler = ^(NSArray *pl ...