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. iOS no visible @interface for 'UIButton' declares the selector errors

    no visible @interface for 'UIButton' declares the selector errors  原理不是特别理解,通过清理缓存,代码更新了,Xcode还是读旧的缓 ...

  2. 字符串—strcpy

    来自——百度百科   原型声明:char *strcpy(char* dest, const char *src); 头文件:#include <string.h> 和 #include ...

  3. Shell 之外 试试不操作 shell 来实现同样的效果

    执行程序时发生了什么当你双击桌面上的终端程序图标时,就会打开一个载入shell的程序. 你键入的命令不会直接在内核执行,而是先和 shell 进行交互.Command (eg. `ls -l')↓Te ...

  4. IOS第一天

    第一天(hello world) 1>UIView所有的控件都继承UIView,倒位置,宽度和高度..UIButton UILable 2>UIViewController .h 是声明属 ...

  5. Error:Unsupported major.minor version 51.0 .

    替换了项目jar文件Tomcat运行报错, 项目开发环境jdk1.6,替换jar文件编译环境是1.7 修改eclipse java ->compiler和Installed JREs 重新编译替 ...

  6. apache查看工作模式及调优

    一,查看工作模式 /usr/sbin/httpd -l Compiled in modules:  core.c  prefork.c  http_core.c  mod_so.c 如果出现prefo ...

  7. Linux下暴力破解工具Hydra详解

    一.简介 Number one of the biggest security holes are passwords, as every password security study shows. ...

  8. Maven-005-部署构件至 nexus 私服

    nexus 私服仓库中宿主仓库主要用于储存装置内部的或一些无法从公共仓库获取的第三方构件,供项目组的人员使用.日常开发中,可将各版本构件直接部署到 Nexus 中对应策略的宿主仓库中.上篇文章中讲述了 ...

  9. LeetCode Two Sum III - Data structure design

    原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...

  10. SQL2005 数据库——查看索引

    sqlserver查询表索引 2012-09-19 18:18 by Spring.Guo, 4599 阅读, 0 评论, 收藏, 编辑 SELECT   索引名称=a.name  ,表名=c.nam ...