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 liwei19900302 at 2011-02-06 13:24:42 on Problem 2387
#include<iostream> 
#include<cstdlib>
#include<cstring>
using namespace std;
#define N 1100
#define INF 0xfffffff
struct Edge
{
	int v,d,next;	
}edge[4100];
int first[N],n,edi,dis[N];
int qur[N],sign[N];
void spfa(int s)
{
	int i,j,u,v;
	int h,e,r;
	
	dis[1]=0;
	for(i=2;i<=n;i++)
		dis[i]=INF;	
	h=r=0;
	memset(sign,0,sizeof(sign));
	qur[h]=s;
	sign[s]=1;
	while(h<=r)
	{
		int u=qur[h++];
		sign[u]=0;
		for(e=first[u];e;e=edge[e].next)
		{
			v=edge[e].v;
			if(dis[u]+edge[e].d<dis[v])
			{
				dis[v]=dis[u]+edge[e].d;
				if(sign[v]==0)
				{
					sign[v]=1;
					qur[++r]=v;
				}
			}
		}	
	}
	return;
}
int main()
{
	int i,j;	
	int t;
	while(scanf("%d%d",&t,&n)!=EOF)
	{
		edi=2;
		memset(first,0,sizeof(first));
		while(t--)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			edge[edi].v=b,edge[edi].d=c;
			edge[edi].next=first[a];
			first[a]=edi;
			edi++;
			edge[edi].v=a,edge[edi].d=c;
			edge[edi].next=first[b];
			first[b]=edi;
			edi++;
		}
		spfa(1);
		printf("%d\n",dis[n]);	
	}
}

此代码正确,但是当将sign[N]数组的名字改为visit[N]就出现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