hdu 1532 Drainage Ditches(最大流)
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.
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.
OutputFor 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 最大流的模板 考虑重边
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const int INF=1e9;
const int N=+;
int mp[N][N];
int vis[N];
int pre[N];
int m,n;
int BFS(int s,int t){
queue<int>q;
memset(pre,-,sizeof(pre));
memset(vis,,sizeof(vis));
pre[s]=;
vis[s]=;
q.push(s);
while(!q.empty()){
int p=q.front();
q.pop();
for(int i=;i<=n;i++){
if(mp[p][i]>&&vis[i]==){
pre[i]=p;
vis[i]=;
if(i==t)return ;
q.push(i);
}
}
}
return false;
}
int EK(int s,int t){
int flow=;
while(BFS(s,t)){
//BFS(s,t);
int dis=INF;
for(int i=t;i!=s;i=pre[i])
dis=min(mp[pre[i]][i],dis);
for(int i=t;i!=s;i=pre[i]){
mp[pre[i]][i]=mp[pre[i]][i]-dis;
mp[i][pre[i]]=mp[i][pre[i]]+dis;
}
flow=flow+dis;
}
return flow;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
memset(mp,,sizeof(mp));
for(int i=;i<n;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
mp[u][v]=mp[u][v]+w;
}
int ans=EK(,m);
cout<<ans<<endl;
} }
hdu 1532 Drainage Ditches(最大流)的更多相关文章
- 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 (最大流)
最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...
- HDU 1532 Drainage Ditches(最大流 EK算法)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...
- HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- hdu 1532 Drainage Ditches(最大流模板题)
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- 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) ...
- HDU 1532 Drainage Ditches (最大网络流)
Drainage Ditches Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) To ...
随机推荐
- JS高级——递归
基本概念 1.在函数内调用函数自己,就是递归 2.没有递归结束条件的递归,就是死递归 3.化归思想,将一个问题由难化易,由繁化简,由复杂化简单的过程称为化归,它是转化和归结的简称. 基本使用 1.计算 ...
- Ajax——模板引擎
模板介绍 1.必要性:ajax请求从服务器接收到大量数据,此时再用普通的字符串拼接是很耗费时间的,这时候模板就有其必要性 2.便利性:插件套用,现在有很多主流的模板插件:BaiduTemplate(百 ...
- Effective Java中文版
译者序 序 前言 第一章 引言 第二章 创建和销毁对象 第1条:考虑用静态工厂方法代替构造函数 第2条:使用私有构造函数强化singleton属性 第3条:通过私有构造函数强化不可实例化属性 第4条: ...
- 小程序 之picker-view省市县
代码地址:https://github.com/yangsphp/area-picker
- Mysql 之show status数据详解
状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...
- php字符串无乱码截取函数封装
/** * * 中英混合字符串长度判断 * @param unknown_type $str * @param unknown_type $charset */ function strLength( ...
- xadmin站点管理类
9. Xadmin xadmin是Django的第三方扩展,比使用Django的admin站点更强大也更方便. 文档:https://xadmin.readthedocs.io/en/latest/i ...
- [forward] cmake, CMakeLists.txt梳理
cmake intro 原文请见 cmake使用总结(转)-工程主目录CMakeList文件编写 在 Linux 下进行开发很多人选择编写 makefile 文件进行项目环境搭建,而makefile ...
- (C/C++学习)4.C++类中的虚函数表Virtual Table
说明:C++的多态是通过一张虚函数表(Virtual Table)来实现的,简称为V-Table.在这个表中,主要为一个类的虚函数的地址表,这张表解决了继承.覆写的问题,保证其真实反应实际的虚函数调用 ...
- 3.git高级篇总结
阅读 Git 原理详解及实用指南 记录 高级 1:不喜欢merge的分叉,用rebase吧 介绍的是 rebase 指令,它可以改变 commit 序列的基础点.它的使用方式很简单: git reba ...