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

求大神指教,为什么RE

Posted by Ash1mar at 2017-08-26 16:11:46 on Problem 2387
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T,N;
int x,y,z;
const int INF=0x3f3f3f3f;
int head[1005],next[2005],to[2005],weight[2005],queue[2010],dis[1005],tot;
bool exist[1005];
void add(int x,int y,int z)
{
	next[++tot]=head[x];
	to[tot]=y;
	head[x]=tot;
	weight[tot]=z;
}
void spfa(int s)
{
	int left=0,right=0,u,v;
	queue[++right]=s;
	exist[s]=true;
	dis[s]=0;
	while(left!=right)
	{
		if(left>2010)
			left=0;
		u=queue[++left];
		exist[u]=false;
		for(int i=head[u];i;i=next[i])
		{
			v=to[i];
			if(dis[v]>dis[u]+weight[i])
			{
				dis[v]=dis[u]+weight[i];
				if(!exist[v])
				{
					exist[v]=true;
					if(right>2010)
						right=0;
					queue[++right]=v;
				}
			}
		}
	}
}
int main()
{
	memset(dis,INF,sizeof(dis));
	while(scanf("%d %d",&T,&N)==2)
	{
		for(int i=1;i<=T;i++)
		{
			scanf("%d %d %d",&x,&y,&z);
			add(x,y,z);
			add(y,x,z);
		}
		spfa(N);
		cout<<dis[1];
	}
	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