HDU 1532 基础EK Drainage Ditches
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11744 Accepted Submission(s): 5519
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 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.
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
#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的更多相关文章
- HDU 1532||POJ1273:Drainage Ditches(最大流)
pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- 【47.63%】【hdu 1532】Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- Drainage Ditches (HDU - 1532)(最大流)
HDU - 1532 题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少? 题解:最大流模板题. #include <iostream> #include <algor ...
- 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) ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
- HDU 1532 Drainage Ditches (最大网络流)
Drainage Ditches Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) To ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 前端JavaScript之BOM
BOM:浏览器对象模型,操作浏览器部分功能的API.比如让浏览器自动滚动. 1.window对象 所有浏览器都支持 window 对象.概念上讲.一个html文档对应一个window对象.功能上讲: ...
- python模块之正则
re模块 可以读懂你写的正则表达式 根据你写的表达式去执行任务 用re去操作正则 正则表达式 使用一些规则来检测一些字符串是否符合个人要求,从一段字符串中找到符合要求的内容.在线测试网站:http:/ ...
- python与consul 实现gRPC服务注册-发现
背景 通过对gRPC的介绍我们知道,当正常启动服务后,我们只需要知道ip,port就可以进行gRPC的连接.可以想到,这种方式并不适合用于线上环境,因为这样直连的话就失去了扩展性,当需要多机部署的时候 ...
- fine ui grid控件添加行号
grid控件的列中添加如下代码<f:RowNumberField EnablePagingNumber="true" TextAlign="Center" ...
- Delphi7程序调用C#写的DLL解决办法(转)
近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行: 编写C#dll的方法都一样,首先在vs2005中创建一个 ...
- ELK+kafka日志处理
此次使用kafka代替redis,elk集群搭建过程请参考:https://www.cnblogs.com/dmjx/p/9120474.html kafka名词解释: 1.话题(Topic):是特定 ...
- java常量池概念【转】
http://blog.csdn.net/olanlanxiari/article/details/8104505
- scrapy--json(360美图)
之前开始学习scrapy,接触了AJax异步加载.一直没放到自己博客,趁现在不忙,也准备为下一个爬虫做知识储存,就分享给大家. 还是从爬取图片开始,先上图给大家看看成果,QAQ. 一.图片加载的方法 ...
- 匿名函数lambda python
lambda 的主体是一个表达式,不是一个代码块lambda 只有一行,仅仅能在lambda表达式种封装有限的逻辑进去匿名函数:需要一个函数,而又不想动脑筋去想名字 #普通函数的定义 def f(a, ...
- lambda & 三元运算
lambda & 三元运算 lambda: 1 >>> def add(x,y): #定义一个加法函数 2 return x+y ...