Drainage Ditches

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

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   |   We have carefully selected several similar problems for you:  1533 3338 1569 3572 3416 
 
 
 
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int dp[][],pre[];
const int tmin=;
int maxflow;
void EK(int start,int end,int n){
while(){
queue<int>q;
q.push();
int minflow=tmin;
memset(pre,,sizeof(pre));
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<=n;i++){
if(dp[u][i]>&&!pre[i]){
pre[i]=u;
q.push(i);
}
}
}
if(pre[end]==)
break;
for(int i=end;i!=start;i=pre[i]){
minflow=min(dp[pre[i]][i],minflow);
}
for(int i=end;i!=start;i=pre[i]){
dp[pre[i]][i]-=minflow;
dp[i][pre[i]]+=minflow;
}
maxflow+=minflow;
}
}
int main(){ int n,m;
while(scanf("%d%d",&m,&n)!=EOF){
memset(dp,,sizeof(dp));
memset(pre,,sizeof(pre));
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
dp[u][v]+=w;
}
maxflow=;
EK(,n,n);
printf("%d\n",maxflow);
}
return ;
}

HDU 1532 基础EK Drainage Ditches的更多相关文章

  1. HDU 1532||POJ1273:Drainage Ditches(最大流)

    pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  2. 【47.63%】【hdu 1532】Drainage Ditches

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

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

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

  4. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

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

    HDU - 1532 题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少? 题解:最大流模板题. #include <iostream> #include <algor ...

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

  7. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

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

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

  9. HDU 1532 Drainage Ditches (网络流)

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

随机推荐

  1. 阿里数据库连接池druid

    官方wiki: https://github.com/alibaba/druid/wiki 实用方法介绍的想当详细,包含监控.扩展.大力推荐!

  2. Hive[6] HiveQL 查询

    6.1   SELECT ... FROM 语句    hive> SELECT name,salary FROM employees;    --普通查询 hive>SELECT e.n ...

  3. Webpack4 学习笔记四 暴露全局变量、externals

    前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 webpack 暴露全局变量 通过 expose-loader 内联配置 在 webpack中配置 每个模块通过注入的方式 通过CD ...

  4. ionic 命令cordova

    安装android platform : ionic platform add android 安装一维码cordova插件 :cordova plugin add https://github.co ...

  5. linux 设置自动关机和重启命令shutdown

    1.shutdown使用命令:Shutdown [选项] [时间] r 关机后立即重启 h 关机 2. 立即关机: shutdown -h now

  6. 路由器基础配置之单臂路由实现vlan间通信

    我们将以上面的拓扑图开始进行配置,目的为设置单臂路由实现vlan间通信,设置4个vlan,pc0,1,2为vlan10 pc3,4,5为vlan20:pc6,7,8为vlan30:server0,1为 ...

  7. redis 面试题

    https://www.cnblogs.com/ftl1012/p/redisExam.html 1. 使用Redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashM ...

  8. php集成开发环境xampp的搭建

    一:运维闲谈 作为一名linux运维工程师,在确保能够有熟练的服务器的搭建和维护优化技能的前提,还需对自身解决问题方法上做出一番功夫. 如何为自己的运维工作添砖加瓦,自动化运维便变得非常重要,一方面, ...

  9. mysql8.0 忘记root密码

    先打开一个cmd:net stop mysql //关闭mysql服务mysqld --shared-memory --skip-grant-tables//跳过登录密码在不关闭第一个CMD的情况下打 ...

  10. sed命令例子详解

    sed -e '/Patricia/h' -e '/Margot/x' datafile 包含Margot的行将被包含Patricia的行替换: sed -e /WE/{h;d;}' -e '/CT/ ...