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 butter at 2007-04-04 20:20:15 on Problem 3217
In Reply To:为什么会 Posted by:butter at 2007-04-04 20:18:04
find2()那个函数莫名其妙的Runtime Error,是不是数据有问题啊

#include <cstdio>

#define MAXN 1101

struct node
{
	int f,m;
	int sex;
	int deep1,deep2;
}vert[MAXN];

int temp[MAXN];

void find1(int i)
{
	if(vert[i].f==i&&vert[i].m==i)
		return;
	vert[vert[i].f].deep1=vert[i].deep1+1;
	vert[vert[i].m].deep1=vert[i].deep1+1;
	find1(vert[i].f);
	find1(vert[i].m);
}

void find2(int i)
{
	if(vert[i].f==i&&vert[i].m==i)
		return;
	vert[vert[i].f].deep2=vert[i].deep2+1;
	vert[vert[i].m].deep2=vert[i].deep2+1;
	find2(vert[i].f);
	find2(vert[i].m);
}

int main()
{
	int p1,p2,i,j,v,t;
	scanf("%i%i",&p1,&p2);

	for(i=1;i<=MAXN-1;i++)
	{
		vert[i].f=vert[i].m=i;
		vert[i].deep1=vert[i].deep2=10;
		vert[i].sex=0;
	}

	while(scanf("%i\n",&v)!=EOF)
	{
		temp[0]=0;
		while(1)
		{
			scanf("%i",&temp[++temp[0]]);
			if(temp[temp[0]]<=0)
			{
				vert[v].sex=temp[temp[0]];
				break;
			}
		}
		if(vert[v].sex==0)
			for(i=1;i<temp[0];i++)
				vert[temp[i]].f=v;
		else for(i=1;i<temp[0];i++)
				vert[temp[i]].m=v;
	}
	if(vert[p1].sex==vert[p2].sex)
	{
		printf("same\n");
		return 0;
	}
	else
	{
		vert[p1].deep1=0;
		find1(p1);
		vert[p2].deep2=0;
		find2(p2);//就是这个函数会RE,不知道为什么
		for(i=1;i<MAXN;i++)
		if((vert[i].deep1<=3)&&(vert[i].deep2<=3))
			{
				printf("close\n");
				goto label;
			}
		printf("marriage\n");
	}
label:	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