Follows 10608.c (Total 52 lines):

/* @JUDGE_ID:4461XX 10608 C */
/* A */
#include<stdio.h>

#define MAX_CITIZEN 30000
int citizen[MAX_CITIZEN+1];
int numGroup[MAX_CITIZEN+1];

int main( void )
{
	int cases, i, j;
	int numCitizen, numPairs, f1, f2, max;

	scanf( "%d", &cases );
	for( ; cases; --cases ){
		scanf( "%d %d", &numCitizen, &numPairs );
		for( i=1; i<=numCitizen; ++i ){
			citizen[i] = i;
			numGroup[i] = 0;
		}

		for( ; numPairs; --numPairs ){
			scanf( "%d %d", &f1, &f2 );
			/*trace f1*/
			while( citizen[f1]!=f1 )
				f1 = citizen[f1];
			/*trace f2*/
			while( citizen[f2]!=f2 )
				f2 = citizen[f2];

			if( f1<f2 )
				citizen[f2] = f1;
			else
				citizen[f1] = f2;
		}

		/*trace all from small to large*/
		for( max=0,i=1; i<=numCitizen; ++i ){
			j = i;
			while( citizen[j]!=j )
				j = citizen[j];
			citizen[i] = j;

			++numGroup[j];
			if( numGroup[j]>max )
				max = numGroup[j];
		}
		printf( "%d\n", max );
	}

	return 0;
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com