more is better

#include<stdio.h>
#include<stdlib.h>
int set[100000],b[100000];
int find(int x)
{return (x==set[x])?x:set[x]=find(set[x]);}
int main()
{
    int n,x,y,max,X,Y;
    while(scanf("%d",&n)!=EOF){
    for(int i=0;i<100000;i++)
    {
            set[i]=i;b[i]=1;
    }
    for( int i=0;i<n;i++){
         scanf("%d%d",&x,&y);
         X = find( x ),Y = find( y );
         if(X!=Y){set[Y] = X;
         b[X]=b[X]+b[Y];}
         }
            max=b[0];
    for(int i=1;i<100000;i++)
            if( b[i]>max)
                max=b[i];
            printf("%d\n",max);
    }
                               return 0;
   
    }
原文地址:https://www.cnblogs.com/QQbai/p/2135268.html