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. process launch failed: Security

    Xcode7/iOS9,真机测试的时候遇到这样的提示 通用-> 描述文件 -> 信任应用

  2. 2.Mysql集群------Mycat读写分离

    前言: Mycat: 一个彻底开源的,面向企业应用开发的大数据库集群 支持事务.ACID.可以替代MySQL的加强版数据库 一个可以视为MySQL集群的企业级数据库,用来替代昂贵的Oracle集群 一 ...

  3. leetcode第221题(最大正方形)的本地IDE实现及变形

    问题描述: 在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积.PS:本文也对只包含0的最大正方形面积进行了运算 示例: 输入: 1 0 1 0 0 1 0 1 1 1 ...

  4. 利用deadline_timer实现定时器Timer

    // 类似QTimer的定时器 class Timer { typedef void(* handler)(); public: Timer() : m_millseconds() , m_timer ...

  5. 【MYSQL笔记2】复制表,在已有表的基础上设置主键,insert和replace

    之前我自己建立好了一个数据库xscj:表xs是已经定义好的 具体的定义数据类型如下: 为了复制表xs,我们新建一个表名为xstext,使用下列语句进行复制xs,或者说是备份都可以: create ta ...

  6. python--Wrapper

    然后给大家介绍的是Wrapper(装饰器),使用广泛.python笔试,面试的话也会百分百问到的,基础和中级的知识储备还是必用的. 让我们开始. 先来一些基础相关知识 *args,**kwargs的区 ...

  7. 面向对象特性 - php

    1.类的字段调用格式 公用字段   类内调用 $this->字段名  类外调用 $对象名->字段名 静态  类内调用 self::$字段名   类外调用 类名::$字段名 常量 类内调用 ...

  8. python——int()函数

    1. 使用 int() 将小数转换为整数,结果是向上取整还是向下取整呢? 小数取整会采用比较暴力的截断方式,即向下取整.(注:5.5向上取整为6,向下取整为5) 2. 我们人类思维是习惯于“四舍五入” ...

  9. POJ :3614-Sunscreen

    传送门:http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...

  10. dijkstra算法与优先队列

    这是鄙人的第一篇技术博客,作为算法小菜鸟外加轻度写作障碍者,写技术博客也算是对自己的一种挑战和鞭策吧~ 言归正传,什么是dijkstra算法呢? -dijkstra算法是一种解决最短路径问题的简单有效 ...