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

哪位高手帮帮小弟看看,为什么老提示Wrong Answer,可是我试了很多的例子都没出错啊..

Posted by xch_4 at 2008-08-16 09:18:39 on Problem 2524
#include<iostream>
using namespace std;
#define max 50050
int father[max];
int gengs[max];
int getfather(int temp)
{
	if(father[temp]==temp)
		return temp;
	 father[temp]=getfather(father[temp]);
	return father[temp];
}
int main()
{
	int n,i,j,stu1,stu2,num=0;
	long m;
	scanf("%d %d",&n,&m);
	while(n!=0||m!=0)
	{
		num++;
		for(i=1;i<=n;i++)
			father[i]=i;
		for(long l=0;l<m;l++)
		{
			scanf("%d %d",&stu1,&stu2);
			int x=getfather(stu1);
			int y=getfather(stu2);
			father[y]=x;
		}
		memset(gengs,0,sizeof(gengs[max]));
		for(i=1;i<=n;i++)
			gengs[getfather(i)]=1;
		int cust=0;
		for(j=1;j<=n;j++)
			cust+=gengs[j];
		printf("Case %d: %d\n",num,cust);
		scanf("%d %d",&n,&m);
	}
	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