Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

狂WA的教训……

Posted by 070220219 at 2010-08-15 17:39:37 on Problem 1459
构图时节点编号从0开始狂wa了好多次,改成编号从1就ac了。费解中……
求开导!

代码:注释掉的代码是编号从0开始的代码。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

const int MN=110;
const int MV=10000*1000;
int c[MN][MN],f[MN][MN],S,T,mf,N,pre[MN],prev[MN],Q[MN*MN];
bool g[MN];

int n,n1,n2,m;

int abs(int x){if(x<0) return -x;return x;}
bool bfs()
{
    int x,y,ss,tt;
    pre[S]=S;
    prev[S]=MV;
    memset(g,false,sizeof(g));
    g[S]=true;
    
    ss=0;
    tt=1;
    Q[ss]=S;
    while(ss<tt){
        x=Q[ss++];
        for(y=1;y<=N;y++){
        //for(y=0;y<N;y++){
            if(!g[y] && f[x][y]<c[x][y]){
                g[y]=!g[y];
                Q[tt++]=y;
                pre[y]=x;
                prev[y]=min(prev[x],c[x][y]-f[x][y]);
                if(y==T)
                    return true;
            }
            if(!g[y] && f[y][x]>0){
                g[y]=!g[y];
                Q[tt++]=y;
                pre[y]=-x;
                prev[y]=min(prev[x],f[y][x]);
                if(y==T)
                    return true;
            }
        }
    }
    return false;
}
void update()
{
    int x,y;
    x=T;
    while(x!=S){
        y=x;
        x=abs(pre[y]);
        if(pre[y]>0)
            f[x][y]+=prev[T];
        if(pre[y]<0)
            f[y][x]-=prev[T];
    }
}
void maxflow()
{
    while(bfs())
        update();
}
void read()
{
    memset(c,0,sizeof(c));
    memset(f,0,sizeof(f));
    S=n+1;
    T=n+2;
    N=n+2;
    /*
    S=n;
    T=n+1;
    N=n+2;
    */
    int x,y,r;
    char ch;
    while(m--){
        scanf(" (%d,%d)%d",&x,&y,&r);
        if(x==y) continue;
        c[x+1][y+1]+=r;
        //c[x][y]+=r;
    }
    while(n1--){
        scanf(" (%d)%d",&x,&r);
        c[S][x+1]=r;
        //c[S][x]=r;
    }
    while(n2--){
        scanf(" (%d)%d",&x,&r);
        c[x+1][T]=r;
        //c[x][T]=r;
    }
}
void output()
{
    mf=0;
    for(int i=1;i<=N;i++)
    //for(int i=0;i<N;i++)
        mf+=f[S][i];
    printf("%d\n",mf);
}
int main()
{
    while(scanf("%d%d%d%d",&n,&n1,&n2,&m)!=EOF){
        read();
        maxflow();
        output();
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator