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

哪位大牛能帮我看一下哪错了?

Posted by dennis1993 at 2010-01-09 11:46:00 on Problem 2987
#include<iostream>
#include<cstdio>
using namespace std;

const __int64 oo=0x6FFFFFFF;

struct NODE{
       int st,ed,f;
       NODE *op,*next;
       NODE(){op=next=NULL;}
       };

const __int64 maxn=5005;

class Maxflow
{
      public :
      
      NODE *g[maxn],*now[maxn],*pre[maxn];

      typedef int Arr1[maxn];

      int m,n;
      int ST,ED;
      int flag;

      Arr1 dis;
      Arr1 back;
      Arr1 sumd;

      Maxflow(){for( int i=0 ;i<maxn ;i++ ) dis[i]=back[i]=sumd[i]=0;}

      void add(int st,int ed,int f)
      {
           NODE *x,*y;
           x=new NODE;
           y=new NODE;
           x->op=y;
           y->op=x;
           x->st=st,x->ed=ed,x->f=f,x->next=g[st],g[st]=x;
           y->st=ed,y->ed=st,y->f=0,y->next=g[ed],g[ed]=y;
      }

      void InitG(){for( int i=1 ;i<=n ;i++ ) g[i]=NULL;}

      void InitNow(){for( int i=1 ;i<=n ;i++ ) now[i]=g[i];}

      __int64 SAP()
      {
          int i,j,k;
          __int64 ans=0;
          int flow=oo;
          for( sumd[0]=n,i=ST ;dis[ST]<n ; )
          {
               flag=false;
               back[i]=flow;
               for( NODE *t=now[i] ;t!=NULL ;t=t->next )
               {
                    j=t->ed;
                    if( t->f<=0 || dis[i]!=dis[j]+1 ) continue;
                    flag=true;
                    now[i]=t;
                    pre[j]=t;
                    flow>t->f?flow=t->f:flow=flow;
                    i=j;
                    if( i==ED )
                    {
                        ans+=flow;
                        while( i!=ST )
                        {
                               pre[i]->f-=flow;
                               pre[i]->op->f+=flow;
                               i=pre[i]->st;
                        }
                        flow=oo;
                   }
                   break;
               }
               if( flag ) continue;
               int Min=n-1;
               for( NODE *t=g[i] ;t!=NULL ;t=t->next )
               if( t->f>0 && dis[t->ed]<Min )
               {
                   now[i]=t;
                   Min=dis[t->ed];
               }
               if( !(--sumd[dis[i]]) ) break;
               sumd[dis[i]=Min+1]++;
               if( i!=ST )
                   i=pre[i]->st,flow=back[i];
          }
          return ans;
      }
};

Maxflow profit;

__int64 n,m;
__int64 sum=0;
__int64 tot=0;

bool vis[5005]={0};

void init(){
     int i,j,k;
     scanf("%d%d",&n,&m);
     profit.ST=n+1;
     profit.ED=profit.n=n+2;
     for( i=1 ;i<=n ;i++ )
     {
          scanf("%d",&k);
          if( k<0 ) profit.add( i,profit.ED,-k );
          else{
              profit.add(profit.ST,i,k);
              sum+=k;
              }
     }
     for( i=1 ;i<=m ;i++ )
     {
          scanf("%d%d",&j,&k);
          profit.add(j,k,oo);
     }
}
     
void DFS(int v)
{
     vis[v]=1;
     if( v!=profit.ST && v!=profit.ED ) tot++;
     int i,j,k;
     for( NODE *t=profit.g[v] ;t!=NULL ;t=t->next ) 
          if( t->f>0 && !vis[t->ed] )
          {
              DFS(t->ed);
          }
}

void doit(){
     int i,j,k;
     k=profit.SAP();
     DFS(profit.ST);
     cout<<tot<<" "<<sum-k<<endl;
     //printf("%I64d ",tot);
     //printf("%I64d\n",sum-k);
}
     

int main()
{
    init();
    doit();
    
    system("pause");
    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