标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11744 Accepted Submission(s): 5519
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<queue> using namespace std; int dp[400][400],pre[400]; const int tmin=999999999; int maxflow; void EK(int start,int end,int n){ while(1){ queue<int>q; q.push(1); int minflow=tmin; memset(pre,0,sizeof(pre)); while(!q.empty()){ int u=q.front(); q.pop(); for(int i=1;i<=n;i++){ if(dp[u][i]>0&&!pre[i]){ pre[i]=u; q.push(i); } } } if(pre[end]==0) break; for(int i=end;i!=start;i=pre[i]){ minflow=min(dp[pre[i]][i],minflow); } for(int i=end;i!=start;i=pre[i]){ dp[pre[i]][i]-=minflow; dp[i][pre[i]]+=minflow; } maxflow+=minflow; } } int main(){ int n,m; while(scanf("%d%d",&m,&n)!=EOF){ memset(dp,0,sizeof(dp)); memset(pre,0,sizeof(pre)); int u,v,w; for(int i=1;i<=m;i++){ scanf("%d%d%d",&u,&v,&w); dp[u][v]+=w; } maxflow=0; EK(1,n,n); printf("%d\n",maxflow); } return 0; }
HDU 1532 基础EK Drainage Ditches
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4679501.html