2011-06-02 13:05:05 #include<iostream> #define N 100010 using namespace std; int n,m,rel[N]; bool root[N]; void init() { int i; for(i=0;i<n;i++) rel[i]=root[i]=1; } int getRoot(int x) { while(!root[x]) x=rel[x]; return x; } void UNION(int rx,int ry) { if(rx!=ry) // 这里要给个判断,就是因为这个,又只得2AC { if(rel[rx]>rel[ry]) { rel[rx]+=rel[ry]; rel[ry]=rx; root[ry]=false; } else { rel[ry]+=rel[rx]; rel[rx]=ry; root[rx]=false; } } } int main() { int i,x,y,rx,ry,ans; scanf("%d%d",&n,&m); init(); for(i=0;i<m;i++) { scanf("%d%d",&x,&y); rx=getRoot(x); ry=getRoot(y); UNION(rx,ry); } for(i=ans=0;i<n;i++) { if(root[i]&&rel[i]>ans) ans=rel[i]; } printf("%d/n",ans); return 0; }