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
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

WA 搞不懂咋回事?路过的大牛指点指点啊!

Posted by 200609020331 at 2008-12-07 13:53:07 on Problem 2457
#include<iostream>
using namespace std;
int graph[1001][1001];
int path[1005];
int top=0;
int bfs(int n)
{
	int u,j;
	int queue[1005],front=0,rear=0;
	bool visit[1005];
	int accout[1005];
	memset(visit,false,sizeof(visit));
	memset(accout,0,sizeof(accout));
	visit[1]=true;
	queue[rear++]=1;
	path[top++]=1;
	while(front<rear)
	{
		u=queue[front++];
		for(j=1;j<=n;j++)
		{
			if(!visit[j] && graph[u][j])
			{
                accout[j]=accout[u]+1;
				visit[j]=true;
				path[top++]=j;
				if(j==n)
					return accout[n];
				queue[rear++]=j;
			}
		}
	}
	return 0;
}

int main()
{
	int i,j,m;
	int n,k,a,b;
	scanf("%d %d",&n,&k);
	for(i=1;i<=k;i++)
		for(j=1;j<=k;j++)
			graph[i][j]=0;
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		graph[a][b]=1;
	}
	m=bfs(k);
	if(m)
	{
		printf("%d\n",m+1);
		for(i=0;i<top;i++)
			printf("%d\n",path[i]);
	}
	else
		printf("-1\n");
	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