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

求大神看下,为什么我的BELLMANFORD过不了,实在觉得逻辑上没错误啊

Posted by xijunlee93 at 2013-04-27 19:57:13 on Problem 3259
#include<iostream>
using namespace std;
long map[1221][1221],d[1200];
int main()
{
    
    int F,N,M,W,i,j,k,l,t,tou,wei,p,find,u,v,pan;
    cin>>F;
    for (l=0;l<F;l++)
    {
       cin>>N>>M>>W;
       for (k=0;k<M;k++)
       {
          cin>>i>>j>>t;
          map[i][j]=map[j][i]=t;
       }
       for (k=0;k<W;k++)
       {
          cin>>i>>j>>t;
          map[i][j]=-t;
       }
       memset(d,214000000,sizeof(d));
       d[1]=0;
       for (k=1;k<N;k++)
       {
         pan=0;
         for (u=1;u<=N;u++) 
          for (v=1;v<=N;v++)
             if (map[u][v])
             if (d[v]>d[u]+map[u][v])
             {
               d[v]=d[u]+map[u][v];
               pan=1; 
             }
         if (pan==0)
         break;
       }
            pan=1;
            for (u=1;u<=N;u++) 
             for (v=1;v<=N;v++)
              if (d[v]>d[u]+map[u][v])
              {pan=0;break;}
            if (pan==1)
            find=0;
            else find=1;
       //}
       if (find==1)
       cout<<"YES"<<endl;
       else cout<<"NO"<<endl;
    }
    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