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 chubuxiao2015 at 2016-05-03 08:45:37 on Problem 3259
附代码:
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1005
int i,j,k,n,m,t,w,u,v,len;
int q[2000000],a[N][N],num[N],dis[N];
bool vis[N];
bool spfa(){
     memset(dis,60,sizeof(dis));
     dis[1]=0;
     int l=1,r=1;
     num[1]=q[1]=vis[1]=1;
     while(l<=r){
         for(int i=1;i<=n;i++)
             if(dis[q[l]]+a[q[l]][i]<dis[i]){
                 dis[i]=dis[q[l]]+a[q[l]][i];

              //   if(dis[i]<0)return 1;

                 if(!vis[i]){
                     vis[i]=1,q[++r]=i,num[i]++;
                     if(num[i]>=n)return 1;
                 }
             }vis[q[l]]=0;l++;
     }return 0;
}
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%d %d %d",&n,&m,&w);
        memset(a,60,sizeof(a)),memset(num,0,sizeof(num)),memset(vis,0,sizeof(vis));
        for(i=1;i<=m;i++){
            scanf("%d %d %d",&u,&v,&len);
            a[u][v]=min(a[u][v],len);
            a[v][u]=min(a[v][u],len);
        }
        for(i=1;i<=w;i++){
            scanf("%d %d %d",&u,&v,&len);
            a[u][v]=min(a[u][v],-len);
        }
        if(spfa())printf("YES\n");
            else printf("NO\n");
    }
    return 0;
}

以上那句注释掉的句子,是导致WA的关键
这题不是说只要回到过去就行了,所以我就想了这个剪枝
但是加了之后就WA了,也就是说一定要有负环,但是题目没说一定要回到原点啊?
有没有大牛解释一下?

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