网络流(Dinic(模板))

Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16467    Accepted Submission(s): 7823

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
 
Source
 
Recommend
lwg
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define MAXN 300
#define INF 9999999
using namespace std;
int N,M,map[MAXN][MAXN],a,b,f,maxflow,pre[MAXN];
void flow(int start,int end){
while(1){
queue<int>q;
/*while(!q.empty())
q.pop();*/
int minflow=INF;
q.push(1);
memset(pre,0,sizeof(pre));
while(!q.empty()){
int u=q.front();
q.pop();
if(u==end) break;
for(int i=1;i<=M;i++)
if(map[u][i]&&!pre[i]){
pre[i]=u;
q.push(i);
}
}
if(pre[end]==0) break;
for(int i=end;i!=start;i=pre[i])
minflow=min(minflow,map[pre[i]][i]);
for(int i=end;i!=start;i=pre[i]){
map[pre[i]][i]-=minflow;
map[i][pre[i]]+=minflow;
}
maxflow+=minflow;
}
}
int main(){
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>a>>b>>f;
map[a][b]+=f;
}
maxflow; //最大流
flow(1,M);
cout<<maxflow;
}

  

- > 网络流(草地排水)的更多相关文章

  1. [网络流]Drainage Ditches(草地排水)

    Drainage Ditches(草地排水) 题目描述 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰 ...

  2. - > 网络流(【最大流】草地排水模板题)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  3. 题解 【USACO 4.2.1】草地排水

    [USACO 4.2.1]草地排水 Description 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫 ...

  4. 草地排水 洛谷P2740 最大流 入门题目

    草地排水 洛谷P2740 最大流入门题目 题意 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一 ...

  5. 【codevs1993】草地排水 最大流

    [codevs1993]草地排水 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段 ...

  6. 【USACO】草地排水

    Drainage Ditches 草地排水 usaco 4.2.1描述在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一 ...

  7. Codevs 1993 草地排水

    1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...

  8. codevs 1993草地排水

    1993 草地排水

  9. AC日记——草地排水 codevs 1993

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  10. codevs1993 草地排水(最大流)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 在农夫约翰的农场上,每逢下雨,Bes ...

随机推荐

  1. git 删除分支如何恢复

    强制删除了一个分支而后又想重新使用这个分支,该怎么找回该分支上的代码呢? 一:问题描述: 今天师父说上线几个功能,让我把开发的分支推送到远程.当打开git就傻眼了,之前开发好的分支被我删除了,就连推送 ...

  2. Android Bitmap转换WebP图片导致损坏的分析及解决方案

    背景 作为移动领域所力推的图片格式,WebP图片在商业领域证明了其应有的价值.基于其他格式的横向对比,其在压缩性能表现,及还原度极为优秀,节省大量的带宽开销.基于可观的效益比,团队早前已开始磋商将当前 ...

  3. NX自动出图 效果图

  4. "HybridDB · 性能优化 · Count Distinct的几种实现方式” 读后感

    原文地址:HybridDB · 性能优化 · Count Distinct的几种实现方式 HybridDB是阿里基于GreenPlum开发的一款MPP分析性数据库,而GreenPlum本身基于Post ...

  5. 对比hive和mysql 复杂逻辑流处理

      1.Mysql中可用存储过程和函数来实现复杂逻辑处理,两者的对比如下:存储过程作为可执行文件,编译一次放在数据库中,函数又返回值.可设定使用权限. 存储过程中可使用游标,声明变量.用call调用. ...

  6. [转]汇编语言:MOVSB,MOVSW,MOVSD

    汇编语言:MOVSB,MOVSW,MOVSD 转自: http://blog.csdn.net/zhenyongyuan123/article/details/8364011   目前80386系列的 ...

  7. 分布式缓存系统Memcached[分享]

    个人网站:http://www.51pansou.com memcached视频下载:memcached视频教程 memcached源码下载:memcached源码 Memcached是什么? Mem ...

  8. codeforces_455B

    B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. 00Enterprise Resource Planning

    Enterprise Resource Planning         企业资源计划即 ERP (Enterprise Resource Planning),由美国 Gartner Group 公司 ...

  10. 17Web应用乱码问题

    Web应用乱码问题 Web应用乱码问题 简介 每个国家(或区域)都规定了本国家(或地区)计算机信息交换用的字符编码集,如美国的扩展ASCII码, 中国的GB2312-80,日本的JIS 等,作为该国家 ...