Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
各位大牛请留意一下,本人用的是以前的模板,为什么我得到是最大流的2倍啊,求解释#include<iostream> #include<memory.h> #include<queue> #include<cstdio> #include <cmath> using namespace std; const int MAX = 110; const int INF = 0x7fffffff; int n, np, nc, m; int cap[MAX][MAX], flow[MAX][MAX], aug[MAX], front[MAX]; queue <int > Q; void max_flow(int s, int e) { int t, i, ans=0; while(1) { memset(aug, 0, sizeof(aug)); memset(front, -1, sizeof(front)); aug[s]=INF; Q.push (s); while(!Q.empty ()) { t=Q.front (); Q.pop (); for(i=s;i<=e;i++) { if(front[i]==-1&&cap[t][i]>flow[t][i]) { front[i]=t; Q.push (i); aug[i]=aug[t]<cap[t][i]-flow[t][i]?aug[t]:cap[t][i]-flow[t][i]; } } } if(!aug[e]) break; ans+=aug[e]; for(i=e;i!=s;i=front[i]) { flow[front[i]][i]+=aug[e]; flow[i][front[i]]-=aug[e]; } ans+=aug[e]; } printf("%d\n", ans/2); } int main() { int i, a, b, c; char temp[30]; while (scanf("%d %d %d %d", &n, &np, &nc, &m) != EOF) { int s=0, e=n+1; memset(cap, 0, sizeof (cap)); memset(flow, 0, sizeof (flow)); for(i=0;i<m;i++) { scanf("%s", temp); sscanf(temp, "(%d,%d)%d", &a, &b, &c); a++, b++; cap[a][b]+=c; } for(i=0;i<np;i++) { scanf("%s", temp); sscanf(temp, "(%d)%d", &a, &b); a++; cap[s][a]+=b; } for(i=0;i<nc;i++) { scanf("%s", temp); sscanf(temp, "(%d)%d", &a, &b); a++; cap[a][e]+=b; } max_flow(s, e); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator