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 ...
随机推荐
- Caffe RPN :error C2220: warning treated as error - no 'object' file generated
在 caffe里面添加rpn_layer.cpp之后,总是出现 error C2220: warning treated as error - no 'object' file generated 这 ...
- C#调用Win32 api时的内存操作
一般情况下,C#与Win 32 Api的互操作都表现的很一致:值类型传递结构体,一维.二维指针传递IntPtr.在Win32 分配内存时,可以通过IntPtr以类似移动指针的方式读取内存.通过IntP ...
- Centos6.7 安装Naigos教程
Centos6.7 安装Naigos教程参考文档:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickst ...
- BeginEditorCommand()
BeginEditorCommand();开始把焦点给CAD CompleteEditorCommand();焦点给窗体
- 15.6.2【Task使用】 组合异步操作
对于C# 5异步特性,我最喜欢的一点是它可以自然而然地组合在一起.这表现为两种不同的 方式.最明显的是,异步方法返回任务,并通常会调用其他返回任务的方法.这些方法可以是直 接的异步操作(如链的最底部) ...
- 洛谷——P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...
- Yin and Yang Stones(思路题)
Problem Description: A mysterious circular arrangement of black stones and white stones has appeared ...
- Linux之FTP/TFTP(vsftp、vsftpd) HTTP(httpd、apache) DHCP(dhcpd)
FTP/TFTP(vsftp.vsftpd): FTP是File Transfer Protocol(文件传输协议)而中文简称为"文传协议".用于Internet上的控制文件的双向 ...
- Python3 编写登陆接口
题目选自 Alex Python自动化开发之路的题目,我是从C++转学Python的,编写的水平有限,轻喷. 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 首先应该有2个txt文件,包含用户 ...
- dubbo服务telnet命令的使用
转自:https://www.cnblogs.com/feiqihang/p/4387330.html dubbo服务发布之后,我们可以利用telnet命令进行调试.管理.Dubbo2.0.5以上版本 ...