标签:namespace cst bsp init pac names std clu can
hdu1856:http://acm.hdu.edu.cn/showproblem.php?pid=1856
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 7 const int maxn=10000005;//有毒,,,,10000010就WA!!!! 8 9 int f[maxn],r[maxn]; 10 int gf(int x) 11 { 12 return x==f[x]?f[x]:f[x]=gf(f[x]); 13 } 14 void uni(int a,int b) 15 { 16 int pa=gf(a); 17 int pb=gf(b); 18 if(pa!=pb) 19 { 20 f[pa]=pb; 21 r[pb]+=r[pa]; 22 } 23 return; 24 } 25 void init() 26 { 27 for(int i=1;i<=maxn;i++) 28 { 29 f[i]=i; 30 r[i]=1; 31 } 32 } 33 34 35 int main() 36 { 37 int n;//为什么n放外面就不行!!!! 38 while(scanf("%d",&n)!=EOF) 39 { 40 init(); 41 int u,v; 42 for(int i=0;i<n;i++) 43 { 44 scanf("%d%d",&u,&v); 45 uni(u,v); 46 } 47 int ans=-1; 48 for(int i=0;i<maxn;i++) 49 { 50 ans=max(ans,r[i]); 51 } 52 printf("%d\n",ans); 53 54 } 55 }
标签:namespace cst bsp init pac names std clu can
原文地址:http://www.cnblogs.com/yijiull/p/6786236.html