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

我所有的测试数据都能过,为什么还是WA呢,郁闷啊

Posted by PC0400322032 at 2004-07-26 16:09:19 on Problem 1708
#include <stdio.h>
#define NT 20000000
void main(void)
{ 
	int n,l,k,q,m,i,j,a,b,c;
	int cr[101];
	int g[101][1000];
	int d[101][101];
	scanf("%d %d %d %d",&n,&l,&k,&q);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&cr[i]);
		g[i][0]=0;
	}
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		g[b][++g[b][0]] = a;
		g[b][++g[b][0]] = c;
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			d[i][j] = NT;
	for(i=1;i<=n;i++)
		d[i][q] = d[q][i] = 0;
	bool fl=true;
	d[q][q] = NT;
	int t=0;
	while(fl)
	{
		fl = false;
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
			{
				if(d[i][j]>=NT)
					continue;
				for(int r=1;r<=g[i][0];r+=2)
				{
					if(g[i][r+1]==cr[j] && d[g[i][r]][j]>d[i][j]+1)
					{
						fl = true;
						d[j][g[i][r]] = d[g[i][r]][j] = d[i][j]+1;
					}
					if(g[j][r+1]==cr[i] && d[g[j][r]][i]>d[i][j]+1)
					{
						fl = true;
						d[i][g[j][r]] = d[g[j][r]][i] = d[i][j]+1;
					}
				}
			}
	}
	if(d[l][k]<NT)
	{
		printf("YES\n");
		printf("%d\n",d[l][k]);
	}
	else
		printf("NO\n");
}

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