POJ1273 Drainage Ditches (最大流+入门题)
2015-08-03 20:25
330 查看
#include<cstdio> #include<algorithm> #include<iostream> #include<cmath> #include<climits> #include<cstring> #include<queue> #include<vector> #include<map> #include<set> using namespace std; int n,m; int cap[210][210]; int flow[210][210]; int a[210]; const int INF=1000000000; int EK(int s,int t) { queue<int> q; memset(flow,0,sizeof(flow)); int p[210]; int f=0; for(;;) { memset(a,0,sizeof(a)); a[s]=INF; q.push(s); while(!q.empty()) { int u=q.front(); q.pop(); for(int v=1;v<=m;v++)if(!a[v]&&cap[u][v]>flow[u][v]) { p[v]=u; q.push(v); a[v]=min(a[u],cap[u][v]-flow[u][v]); } } if(a[t]==0)break; for(int u=t;u!=s;u=p[u]) { flow[p[u]][u]+=a[t]; flow[u][p[u]]-=a[t]; } f+=a[t]; } return f; } int main() { while(~scanf("%d%d",&n,&m)) { memset(cap,0,sizeof(cap)); for(int i=0;i<n;i++) { int s,e,c; scanf("%d%d%d",&s,&e,&c); /*if((cap[s][e]==0)||(cap[s][e]!=0&&c>cap[s][e])) { cap[s][e]=c; //cap[e][s]=0; }*/ cap[s][e]+=c; } printf("%d\n",EK(1,m)); } return 0; }
相关文章推荐
- HDU 1532 Drainage Ditches(最大流)
- 服务器中很多的CLOSE_WAIT
- Traffic jam caused by the rain (3rd Aug.2015)
- 【HDOJ 1532】 Drainage Ditches(最大流模板)
- selection does not contain a main type
- JetBrains全系列注册机
- 2015 Multi-University Training Contest 4
- Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
- J - Air Raid - hdu 1151(最小边覆盖)
- 2015 Multi-University Training Contest 4 hdu 5338 ZZX and Permutations
- 论文提要“Pedestrian Detection aided by Deep Learning Semantic Tasks”
- URAL 1900. Brainwashing Device(dp+输出路径)
- LeetCode #217 Contains Duplicate
- BUPT Summer Training #7 for Grade 14 题解
- hdu 1532 Drainage Ditches(最大流ek+dinic)
- [LeetCode]#11 Container With Most Water
- 解决服务器存在大量time_wait的问题
- 杭电(hdu)1702 ACboy needs your help again!
- POJ 3250 Bad Hair Day(单调栈)
- ADT 启动报错