Drainage DitchesHal Burch
Time Limit 1000 ms
Memory Limit 65536 kb
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. Note however,
that there can be more than one ditch between two intersections.
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
Input file contains multiple test cases.
In a test case:
Line 1: 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.
Line 2..N+1: Each of 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,One line with 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
USACO 4.2

题意:就是给出各个边的最大流量,和起点终点,求最大流。

Edmonds-Karp 增广路算法

Code:

//Edmondes-Karp
#include <cstdio>
#include <cstring>
#include <queue>
#define INF 0x7fffffff
using namespace std;
queue<int> q;
const int maxn = 200;
int n, m, ans;
int next[maxn+10], p[maxn+10], f[maxn+10][maxn+10], cap[maxn+10][maxn+10];
int Edmondes_Karp(int s, int t) {
int ans = 0, v, u;
queue<int> q;
memset(f,0,sizeof(f));
while(true) {
memset(p,0,sizeof(p));
p[s] = INF;
q.push(s);
while(!q.empty()) { //BFS找增广路
int u = q.front();
q.pop();
for(v=1; v<=m; v++)
if(!p[v]&&cap[u][v]>f[u][v]) { //找到新节点v
next[v] = u; //记录v的父亲,并加入FIFO队列
q.push(v);
p[v] = p[u] < cap[u][v]-f[u][v]?p[u] : cap[u][v] - f[u][v];
//s-v路径上的最小残量
}
}
if(!p[t]) break; //找不到增广路,则当前流已经是最大流
for(u=t; u!=s; u= next[u]) { //从汇点往回走
f[next[u]][u] +=p[t];//更新正向流量
f[u][next[u]] -=p[t];//更新反向流量
}
ans += p[t]; //更新从s流出的总流量
}
return ans;
}
int main() {
int i, k, k1, k2, k3;
while(~scanf("%d%d",&n,&m)) {
memset(cap,0,sizeof(cap));
for(i=1; i<=n; i++) {
scanf("%d%d%d",&k1,&k2,&k3);
cap[k1][k2] +=k3;
}
printf("%d\n",Edmondes_Karp(1,m) );
}
return 0;
}

POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)的更多相关文章

  1. poj 1273 && hdu 1532 Drainage Ditches (网络最大流)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53640   Accepted: 2044 ...

  2. hdu 1532 Drainage Ditches (最大流)

    最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...

  3. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

  4. HDU 1532 Drainage Ditches(最大流 EK算法)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...

  5. HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...

  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 (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  8. 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) ...

  9. HDU 1532 Drainage Ditches (最大网络流)

    Drainage Ditches Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) To ...

随机推荐

  1. 关于高斯消元解决xor问题的总结

    我觉得xor这东西特别神奇,最神奇的就是这个性质了 A xor B xor B=A 这样就根本不用在意重复之类的问题了 关于xor的问题大家可以去膜拜莫队的<高斯消元解XOR方程组>,里面 ...

  2. 流行的MySql版本

    简介 MySQL是历史上最受欢迎的免费开源程序之一.它是成千上万个网站的数据库骨干,并且可以将它(和Linux)作为过去10年里Internet呈指数级增长的一个有力证明. 那么,如果MySQL真的这 ...

  3. RHCS集群

    理论基础: User → HA →     Lb    → web → sql → 分布式filesystem ->磁盘I/O 用户   高可用 负载均衡    应用   数据库      mf ...

  4. 【转】Android AlertDialog 点击对话框外部区域不关闭的设置

    原文网址:http://blog.sina.com.cn/s/blog_8f1c79dd0101a63u.html 在Android开发中,常常需要调用对话框,但会遇到这样一种情况,在显示对话框的时候 ...

  5. 导出Excel帮助类

    using System; using System.Collections.Generic; using System.Text; using System.Data; using System.D ...

  6. Javascript 对输入框中的内容进行 “全选/反选”

    <</span>script> document.write("<</span>ul>"); for(var i=0;i<&l ...

  7. HDU 3085 Nightmare Ⅱ 双向BFS

    题意:很好理解,然后注意几点,男的可以一秒走三步,也就是三步以内的都可以,鬼可以穿墙,但是人不可以,鬼是一次走两步 分析:我刚开始男女,鬼BFS三遍,然后最后处理答案,严重超时,然后上网看题解,发现是 ...

  8. 求一字符串最长不重复字符子串的长度【Java 版】

    一. 前言 最近学习有点断断续续,整理的一些知识点要么不完整,要么完全没搞懂,不好拿上台面,还是先在草稿箱躺着吧.偶尔在浏览大牛博客http://coolshell.cn的时候,发现大牛业余时间也在做 ...

  9. selenium在chrome上运行报 Element is not clickable at point (1096, 26)

    Firefox上正常运行的脚本在chrome上提示Element is not clickable at point (1096, 26).分析原因,首先肯定不是因为页面元素不存在而无法点击.也不是要 ...

  10. 《转》GDB中应该知道的几个调试方法

    原文:http://coolshell.cn/articles/3643.html 七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询问我关于GDB ...