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 Varick_Q at 2011-02-16 16:14:24 on Problem 2524
#include <iostream>
using namespace std;

int fa[50001];
int getfa(int x){
	return 	fa[x]==x?x:fa[x]=getfa(fa[x]);
}
void Union(int x,int y){
    fa[getfa(x)] = getfa(y);
}
int main()
{
//	freopen("in.txt","r",stdin);
	int n,m,i,x,y;
	for(int k =1 ; ; k ++){
		scanf("%d %d", &n, &m);
		if(n == 0 && m == 0) break;
		for(i =1 ; i <= n ; i ++)
			fa[i] = i;
		for(i =1 ; i <= m ; i ++){
			scanf("%d %d", &x, &y);
			if(getfa(x) != getfa(y))
				n--;
			Union(x,y);
		}
		printf("case %d: %d\n", k, n);
	}
	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