HDU 1532.Drainage Ditches-网络流最大流
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22789 Accepted Submission(s): 10905
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.
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
#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-网络流最大流的更多相关文章
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- 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(最大流) USACO 93
最大流首次体验感受—— 什么是最大流呢? 从一个出发点(源点),走到一个目标点(汇点),途中可以经过若干条路,每条路有一个权值,表示这条路可以通过的最大流量. 最大流就是从源点到汇点,可以通过的最大流 ...
- HDU 1532 Drainage Ditches(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- HDU 1532 Drainage Ditches(最大流 EK算法)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- HDU 1532 Drainage Ditches (最大网络流)
Drainage Ditches Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) To ...
随机推荐
- [剑指Offer] 43.左旋转字符串
题目描述 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=”abc ...
- [剑指Offer] 11.二进制中1的个数
[思路]如果一个整数不为0,那么这个整数至少有一位是1.如果我们把这个整数减1,那么原来处在整数最右边的1就会变为0,原来在1后面的所有的0都会变成1(如果最右边的1后面还有0的话).其余所有位将不会 ...
- ng依赖注入
依赖注入 1.注入器在组件的构造函数中写服务constructor(private httpreq:HttpService) { } 2.提供器 providers: [HttpService],
- ACM模板~求逆序对的个数
#include <map> #include <set> #include <cmath> #include <ctime> #include < ...
- js中连写两个?:三元运算符语法解释
在angular 源码中有连写两个三元运算符的代码: var hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() :$loc ...
- ERROR: Found lingering reference file hdfs
Found lingering reference异常 ERROR: Found lingering reference file hdfs://jiujiang1:9000/hbase/month_ ...
- node搭建文件服务器
python可以在目录下python -m http.server 8080来启动一个静态文件服务器,使用node实现一个 运行node fileServer.js D:\lanFeature 即可将 ...
- 精通javascript笔记(智能社)——简易tab选项卡及应用面向对象方法实现
javascript代码(常规方式/面向过程): <script type="text/javascript"> window.onload=function(){ v ...
- UOJ#80 二分图最大权匹配 [模板题]
从前一个和谐的班级,有 nlnl 个是男生,有 nrnr 个是女生.编号分别为 1,…,nl1,…,nl 和 1,…,nr1,…,nr. 有若干个这样的条件:第 vv 个男生和第 uu 个女生愿意结为 ...
- html5 游戏开发
近来想做html5游戏开发些小东西玩一下,因为手边就是笔记本,想怎么玩就怎么玩了,今年可以说是非常重要特殊的一年,感觉有些倒霉,不过,心态最重要,该怎么做的时候就去怎么做吧,日子的24小时是不会变的, ...