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

哪位大牛帮我看一下……discuss里的数据都通过了,还是WA,贴下代码……

Posted by windyfly at 2010-07-18 15:44:14 on Problem 1308
#include<stdio.h>
#include<string.h>
#define inf 0x3f3f3f3f
int u[100010];
int degree[100010];
int pd(int x)
{
	if(u[x]!=x)
		u[x]=pd(u[x]);
	return u[x];
}
int main()
{
	int a,b;
	bool mark=1;
	int k=1,i;
	for(i=0;i<100010;i++)
		u[i]=i;
	memset(degree,inf,sizeof(degree));
	int num;
	while(scanf("%d%d",&a,&b))
	{

		if(a==-1&&b==-1)
			break;
		else
		 if(a==0&&b==0)
		 {
			 num=0;
              for(i=0;i<100010;i++)
				  if(degree[i]==0)
					  num++;
              if(mark==1&&num==1)
				  printf("Case %d is a tree.\n",k++);
			  else
				  printf("Case %d is not a tree.\n",k++);
			  for(i=0;i<100010;i++)
		               u[i]=i;
			  mark=1;
			  memset(degree,inf,sizeof(degree));
		 }
		 else
		 {
			 if(pd(a)!=pd(b)&&mark==1)
			 {
				 u[pd(a)]=pd(b);
			     if(degree[a]==inf)
					 degree[a]=0;
				 else
					 degree[b]=1;
			 }
			 else
				 mark=0;
		 }
		 
	}
	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