HDU 1532 Drainage Ditches(最大流+EK算法模板题)
来源:互联网 发布:网络验证系统哪个好 编辑:程序博客网 时间:2024/06/04 20:03
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.
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.
5 41 2 401 4 202 4 202 3 303 4 10
50
题解:
源点为1,汇点为n,给num个流,让你求最大流。。。EK模板题目,虽然网络流刚刚入门的我不太懂但是直接按着紫书上的模板打了一遍,修改了些就ac了
模板会用就行了qwq
代码:
#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<vector>#include<deque>#include<algorithm>using namespace std;#define INF 100861111#define ll long long#define eps 1e-5#define maxn 205struct edge//存边{ int from,to,cap,flow;//cap为容量,flow为流量 edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f){}};vector<edge>ed;vector<int>G[maxn];//存第i个点连接的第j条边的标号int a[maxn];//存起点到i的可改进量。。不太懂,照着紫书打的int p[maxn];//最短路树上p的入弧编号int m,n;void init(){ for(int i=1;i<=n;i++) G[i].clear(); ed.clear();}void addEdge(int from,int to,int cap){ ed.push_back(edge(from,to,cap,0)); ed.push_back(edge(to,from,0,0));//反向加边 m=ed.size(); G[from].push_back(m-2); G[to].push_back(m-1);}int Maxflow(int s,int t)//s为源点,t为汇点{ int flow=0; while(1) { memset(a,0,sizeof(a)); queue<int>q; q.push(s); a[s]=INF; while(!q.empty()) { int x=q.front(); q.pop(); for(int i=0;i<G[x].size();i++) { edge &e=ed[G[x][i]]; if(!a[e.to]&&e.cap>e.flow) { p[e.to]=G[x][i]; a[e.to]=min(a[x],e.cap-e.flow); q.push(e.to); } } if(a[t]) break; } if(!a[t]) break; for(int e=t;e!=s;e=ed[p[e]].from) { ed[p[e]].flow+=a[t]; ed[p[e]^1].flow-=a[t]; } flow+=a[t]; } return flow;}int main(){ int i,j,x,y,c,num; while(scanf("%d%d",&num,&n)!=EOF) { init(); for(i=0;i<num;i++) { scanf("%d%d%d",&x,&y,&c); addEdge(x,y,c); } printf("%d\n",Maxflow(1,n)); } return 0;}
阅读全文
0 0
- HDU 1532 Drainage Ditches(最大流+EK算法模板题)
- hdu 1532 Drainage Ditches (最大流—EK算法)
- HDU ACM 1532 Drainage Ditches->网络最大流模版题(EK算法实践)
- hdu 1532 Drainage Ditches (最大流EK算法)
- HDU 1532 Drainage Ditches——最大流EK算法
- hdu 1532 Drainage Ditches 网络最大流模板 EK + Dinic两种算法AC
- HDU 1532-Drainage Ditches(网络最大流,EK,Ford-Fulkerson,dinic3种算法套模板)
- hdu 1532 Drainage Ditches(EK算法)
- hdu 1532 Drainage Ditches(最大流ek+dinic)
- poj 1273 & hdu 1532 Drainage Ditches(最大流 )EK,dinic模板
- hdu 1532 Drainage Ditches(最大流 三种模板:EK、Dinic、isap)
- poj 1273 Drainage Ditches(最大流的EK算法模板)
- (POJ1273)Drainage Ditches(裸最大流,EK模板)
- hdu1532--Drainage Ditches(最大流(EK算法))
- HDU 1532 Drainage Ditches (最大流模板)
- hdu 1532 poj 1273 Drainage Ditches (ek算法)
- hdu1532-Drainage Ditches(最大流&EK)
- HDU 1532Drainage Ditches(最大流模板题 ISAP)
- CSS布局学习笔记and一些小技巧
- 前置配置
- tensorflow 的MNIST实现
- VMware中三种网络模式设置指南
- nagios安装后提示 statusmap.cgi找不到的解决办法
- HDU 1532 Drainage Ditches(最大流+EK算法模板题)
- python删除重复文件代码
- 【python】采集免费代理ip并验证可用性后存储到文件
- slidingmenu左右侧滑页面
- 火狐浏览器安全插件
- js实现复制到剪切板
- HDU-5512-Pagodas
- bzoj4953 [Wf2017]Posterize(区间dp)
- bzoj 1629: [Usaco2007 Demo]Cow Acrobats(贪心排序)