Drainage Ditches

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
 
题意:最大流EK算法,一直找增广路径(BFS),假如有,记录增广路的最小值k,ans +=k ,并更新网络的值(要用反向边)。复杂度O(V*E^2)
题解:最大流模版
#include<bits/stdc++.h>
#define N 205
#define mes(x) memset(x, 0, sizeof(x));
#define ll __int64
const long long mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
int plat[N][N], n, dir[N], pre[N];
int bfs(int s,int e){
int t, i;
queue<int>q;
memset(dir,,sizeof(dir));
memset(pre,-,sizeof(pre));
pre[s] = s;
dir[s] = ;
q.push(s);
while(!q.empty()){
t = q.front();
q.pop();
for(i=;i<=n;i++){
if(plat[t][i] > &&!dir[i]){//全为正且未走过即扩展
pre[i] = t;
dir[i] = ;
if(i == e) return ;//扩展到终点为止
q.push(i);
}
}
}
return ;//找不到
}
int EK(int s,int e){
int ans=,minn,i;
while(bfs(s,e)){
minn = MAX;
for(i=e;i!=s;i=pre[i])
if(minn > plat[pre[i]][i])
minn = plat[pre[i]][i];
for(i=e;i!=s;i=pre[i]){
plat[pre[i]][i] -= minn;
plat[i][pre[i]] += minn;
}
ans += minn; }
return ans;
}
int main()
{
int m, a, b, c;
while(~scanf("%d%d", &m, &n)){
mes(plat);
while(m--){
scanf("%d%d%d", &a, &b, &c);
plat[a][b] += c;
}
printf("%d\n", EK(,n));;
}
return ;
}
 

HDU1532 Drainage Ditches 网络流EK算法的更多相关文章

  1. Drainage Ditches(网络流(EK算法))

    计算最大流,EK算法模板题. #include <stdio.h> #include <string.h> #include <queue> using names ...

  2. HDU-1532 Drainage Ditches,人生第一道网络流!

    Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...

  3. HDU1532 Drainage Ditches —— 最大流(sap算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...

  4. hdu-----(1532)Drainage Ditches(最大流问题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU1532_Drainage Ditches(网络流/EK模板/Dinic模板(邻接矩阵/前向星))

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. NYOJ 323 Drainage Ditches 网络流 FF 练手

    Drainage Ditches 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 Every time it rains on Farmer John's fields, ...

  7. POJ 1459 网络流 EK算法

    题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...

  8. 最大网络流 EK 算法

    网络流是什么类型的问题,看一道题目你就知道了 点击打开链接 . 默认具备图论的基本知识,网络流概念比较多,先看看书熟悉一下那些概念.比较好!一个寄出的网络最大流.EK算法写的. 这是一幅网络,求S   ...

  9. POJ 1273 Drainage Ditches (网络流Dinic模板)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

随机推荐

  1. jQuery判断元素是否存在方法总结

    在jquery中判断元素是否存在我们可使用$("#div").length > 0)来判断了,意思就是判断元素长度了,如果没有肯定是不存在的哦,下面我来介绍介绍. 使用传统j ...

  2. PHP版本VC6与VC9、Thread Safe与None-Thread Safe等的区别

    PHP版本VC6与VC9.Thread Safe与None-Thread Safe等的区别 [摘要]PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,在PHP发 ...

  3. 20145224&20145238《信息安全系统设计基础》实验四

    20145224陈颢文20145238荆玉茗 <信息安全系统设计基础>第四次实验报告 课程:信息安全系统设计基础 班级: 1452 姓名:荆玉茗 陈颢文 学号:20145238 20145 ...

  4. 腾讯QQ内测群新功能:QQ万人群即将袭来!

    4月6日早晨有人爆出QQ群正在内部测试QQ万人群的消息,此消息一出,网友们都不蛋定了,各种议论纷纷,可是唯独腾讯没有做出任何有关这方面的解释. QQ是要准备让上万个人在一个群聊天吗? 那不会被刷屏刷死 ...

  5. python随机服务器的双线出口ip发送邮件

    #-*- coding:utf-8 -*-import smtplibimport sysimport random import socketfrom email.mime.text import ...

  6. nginx反向代理(proxy_pass)tomcat的过程中,session失效的问题解决

    Nginx反向代理tomcat,很是方便,但是也有些细节的问题需要注意:今天遇到了这样一个问题,tomcat中路径“host/web1”,nginx中直接“host/”代理,这时候session就无法 ...

  7. 关于int,long,long long

    偶然的,我同学给我发了一个面试题:long 占多少字节 对于这个问题我也不好多说,有时候可能会想的比较多,这个题也需要多想一下 <1>在16位机器上,int 2字节, long 4字节, ...

  8. iOS 两个App之间调起通信

    前言 假设需求是这样的:由一个app1跳转到app2之后,app2完成某项任务之后,怎么把app2的完成信息传到app1(自己的程序是app1),传的是什么类型的数据,怎么进行解析? 逻辑 本文章使用 ...

  9. 关于js SDK的程序,java SDK的程序

    一:JS SDK 1.修改配置workspace 2.导入 3.Demo.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Trans ...

  10. Wordpress实现站搜索

    wordpress内置的搜索表单如下 <form role="search" method="get" id="searchform" ...