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. DateFormatUtil.java

    package com.vcredit.framework.utils; import java.sql.Timestamp;import java.text.DateFormat;import ja ...

  2. Python 第一课

    Python语言特点: 优雅,明确,简单 适合开发: Web网络和各种网络服务 系统工具和脚本 作为胶水语言把其他语言开发的模块包装起来方便使用 Python2.7.10的安装(path环境变量)   ...

  3. BizTalk动手实验(十)业务活动监控(BAM)演示

    1 课程简介 通过本课程熟悉业务活动监控(BAM)的使用及各组件的配置. (本环境为Windows 2008 32位操作系统环境 + Visual Studio 2010 + BizTalk 210) ...

  4. Android课程---Android 如何用滑杆(SeekBar)组件设置图片颜色的透明度(转)

    Android系统支持的颜色是由4个值组成的,前3个为RGB,也就是我们常说的三原色(红.绿.蓝),最后一个值是A,也就是Alpha.这4个值都在0~255之间.颜色值越小,表示该颜色越淡,颜色值越大 ...

  5. 用Scala实现集合中相邻元素间的差值

    欢迎转载,转载请注明出处,徽沪一郎. 概要 代码这东西,不写肯定不行,新学Scala不久,将实际遇到的一些问题记录下来,日后也好查找. 今天讲的是如何计算同一集合中元素两两之间的差值,即求开始集合(a ...

  6. Why MySQL could be slow with large tables ?

    https://www.percona.com/blog/2006/06/09/why-mysql-could-be-slow-with-large-tables/

  7. 11高级网站构建:div和span

    用<div>元素把属于一个逻辑部分的元素包围起来.可以用id属性为<div>提供一个唯一的标签. <div>的作用:1.更深一步展示页面的基本逻辑结构(相当于一个逻 ...

  8. lleetcode 292. Nim Game

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  9. The best career advice I’ve received

    I recently had an interesting discussion with a colleague. We were recounting our job histories and ...

  10. 创建一个程序,从应用程序中随机添加N名参加歌唱比赛的同学,并随机对这N名同学的比赛按姓名的拼音先后顺序进行排序

    public class Pint { /** * 姓名 */ public String name; /** * 年龄 */ public String age; public Pint(){ } ...