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:哪位能给看看阿?怎么老RE呢?!

Posted by lironghua at 2007-09-24 20:52:00 on Problem 1611
In Reply To:哪位能给看看阿?怎么老RE呢?! Posted by:liao14 at 2007-09-12 01:10:06
> #include<stdio.h>
> 
> int father[30001],i,j;
> 
> void init(int n)
> {
> 	for(i=0;i<n;i++)father[i]=i;
> }
> 
> int find(int p)
> {
> 	if(father[p]!=p) father[p]=find(father[p]);
> 	return father[p];
> }
> 
> int main()
> {
> 	int n,m;
> 	
> 	while(1)
> 	{
> 		scanf("%d",&n);
> 		if(!n) break;
> 		scanf("%d",&m);
> 		init(n);
> 		int k,tmp1,tmp2;
> 		for(i=0;i<m;i++)
> 		{
> 			scanf("%d",&k);
> 			scanf("%d",&tmp1);
> 			for(j=1;j<k;j++)
> 			{
> 				scanf("%d",&tmp2);
> 				father[find(tmp2)]=tmp1;
> 			}
> 		}
> 		father[find(0)]=0;
> 		father[0]=0;
> 		int ans=1;
> 		for(i=1;i<n;i++)
> 			if(find(i)==0) ans++;
> 		printf("%d\n",ans);	
> 	}
> 	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