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 |
我的也是G++过,不过C++ TLE,在浙大没这个问题。。。什么道理呢??In Reply To:g++过了,c++wa。我查了很久查不出来。我机子里没有vc,哪位帮我调一下?谢谢!! Posted by:tengshengbo at 2005-08-09 12:22:33 #include<iostream> using namespace std; #define MAXN 102 #define inf 1000000000 #define MIND 0 int max_flow(int n,int mat[][MAXN],int source,int sink){ int pre[MAXN],que[MAXN],p,q,t,i; int d[MAXN],flow[MAXN][MAXN],j; if (source==sink) return inf; memset(flow,0,sizeof(flow)); while(1){ memset(pre,-1,sizeof(pre)); pre[t=source]=source; d[t]=inf; for (p=q=0;p<=q&&pre[sink]<0;t=que[p++]) for (i=0;i<n;i++) if (pre[i]<0&&(j=mat[t][i]-flow[t][i])>MIND) pre[que[q++]=i]=t,d[i]=d[t]<j?d[t]:j; else if (pre[i]<0&&(j=flow[i][t])>MIND) pre[que[q++]=i]=-t,d[i]=d[t]<j?d[t]:j; if (pre[sink]<0) break; for (i=sink;i!=source;) if (pre[i]>=0) flow[pre[i]][i]+=d[sink],i=pre[i]; else flow[i][-pre[i]]-=d[sink],i=-pre[i]; } for (j=i=0;i<n;j+=flow[source][i++]); t=j; return t; } int main() { int n,np,nc,m,i,u,v; int z,mat[102][102]; char c; while(scanf("%d %d %d %d",&n,&np,&nc,&m)!=EOF) { memset(mat,0,sizeof(mat)); for(i=0;i<m;i++) { while(scanf("%c",&c),c!='('); scanf("%d",&u); while(scanf("%c",&c),c!=','); scanf("%d",&v); while(scanf("%c",&c),c!=')'); scanf("%d",&z); mat[u][v]=z; } for(i=0;i<np;i++) { while(scanf("%c",&c),c!='('); scanf("%d",&u); while(scanf("%c",&c),c!=')'); scanf("%d",&z); mat[n][u]=z; } for(i=0;i<nc;i++) { while(scanf("%c",&c),c!='('); scanf("%d",&u); while(scanf("%c",&c),c!=')'); scanf("%d",&z); mat[u][n+1]=z; } cout<<max_flow(n+2,mat,n,n+1)<<endl; } } 试过去除函数调用,会WA,说明输入没问题。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator