HDU 1856 - More is better
裸的并查集
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 const int maxn=10000000; 5 int n; 6 int f[maxn+5],v[maxn+5]; 7 int sf(int x){ 8 return f[x]==x? x: f[x]=sf(f[x]); 9 } 10 int a,b,fa,fb; 11 int main() 12 { 13 while(~scanf("%d",&n)) 14 { 15 for(int i=1;i<=maxn;i++) f[i]=i,v[i]=0; 16 for(int i=1;i<=n;i++) 17 { 18 scanf("%d%d",&a,&b); 19 fa=sf(a); fb=sf(b); 20 f[fa]=fb; 21 } 22 int ans=0; 23 for(int i=1;i<=maxn;i++) 24 { 25 fa=sf(i); 26 v[fa]++; 27 ans=max(ans,v[fa]); 28 } 29 printf("%d\n",ans); 30 } 31 }
我自倾杯,君且随意