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 SerokSSR at 2018-12-16 19:59:17 on Problem 1611
RT。

code:

#include<cstdio>
int father[30010],n,m,s,x,y; 
int getroot(int x) {
	father[x]=father[father[x]];
	if(father[x]==x) return x;
	return getroot(father[x]);
}
int main() {
	//freopen("suspect.in","r",stdin);
	//freopen("suspect.out","w",stdout);
	while(scanf("%d%d",&n,&m)!=EOF and n||m) {
		for(int i=0;i<n;i++) father[i]=i;
		for(int i=0;i<m;i++) {
			scanf("%d%d",&s,&x);
			int x1=getroot(x);
			for(int j=1;j<s;j++) {
				scanf("%d",&y);
				int y1=getroot(y);
				if(x1!=y1) father[x1]=y1;
			}
		}
		int x0=getroot(0),p=0;
		for(int i=0;i<n;i++)
			if(getroot(i)==x0) p++;
		printf("%d\n",p);
	}
	
	//fclose(stdin);
	//fclose(stdout);
	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