【poj1273】Drainage Ditches(ISAP模板)
2016-07-14 11:46
435 查看
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 68458 Accepted: 26510
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 41 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50Isap模板
跪求大神给出指点建议
Orzorzorzorzorz
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #define N 405 #define inf 2000000000 using namespace std; struct Edge { int from,to,cap,next; }edge[N<<2]; int n,m,tot; int first ,cur ,d ,cnt ,pre ; int aug ; inline void Add_Edge(int a,int b,int c) { edge[++tot].to=b; edge[tot].from=a; edge[tot].cap=c; edge[tot].next=first[a]; first[a]=tot; } inline int ISAP(int s,int t) { memset(d,0,sizeof(d)); memset(cnt,0,sizeof(cnt)); for(int i=0;i<=m;i++)cur[i]=first[i]; int x,i; int ans=0; pre[s]=-1; aug[s]=inf; x=s; while(d[s]<m) { if(x==t) { ans+=aug[t]; int auge=aug[t]; for(int v=pre[t];v!=-1;v=pre[v]) { int j=cur[v]; edge[j].cap-=auge; edge[j^1].cap+=auge; aug[edge[j].to]-=auge; if(edge[j].cap==0)x=v; } } for(i=cur[x];i!=-1;i=edge[i].next) { int j=edge[i].to; if(edge[i].cap>0 && d[x]==d[j]+1) { aug[j]=min(aug[x],edge[i].cap); cur[x]=i; pre[j]=x; x=j; break; } } if(i==-1) { if(--cnt[d[x]]==0) { break; } cur[x]=first[x]; d[x]++; cnt[d[x]]++; if(x!=s)x=pre[x]; } } return ans; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { tot=1; memset(first,-1,sizeof(first)); for(int i=1;i<=n;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); Add_Edge(a,b,c); Add_Edge(b,a,0); } printf("%d\n",ISAP(1,m)); } }
相关文章推荐
- Poj2638 网络流+最短路+二分答案
- BZOJ3275 Number (最小割)
- [笔记] 网络流-最大流 POJ-1273\HDU-4240
- 上下界网络流初探
- Edmonds-Karp 最大流 hdu 1532 Drained Ditches
- 网络流_poj1273
- POJ 1273 Drainage Ditches 最大流 dinic
- POJ1273-Drainage Ditches
- 【网络流】复杂的大门
- ACM/ICPC World Finals 2013 C Surely You Congest
- 北京集训队 2016 Day4 alarm
- 网络流算法整理
- 网络流最大流之SAP算法 详解
- [BZOJ1797][AHOI2009][最大流][强连通分量]Mincut最小割
- [BZOJ2324][ZJOI2011][最小费用最大流]营救皮卡丘
- [BZOJ1834][ZJOI2010][最大流][最小费用最大流]网络扩容
- Topcoder SRM642 TaroCutting
- POJ2391解题报告
- uva 11248
- 【学习】网络流