#include
using namespace std;
const int MAX=10000005;
typedef struct n
{
int pre;
int num;
n(int a=1) :num(a) {}
}N;
N pe[MAX];
int find(int x)
{
int r=x,j;
while(pe[r].pre!=r)
r=pe[r].pre;
while(pe[x].pre!=r)
{
j=pe[x].pre;
pe[x].pre=r;
x=j;
}
return r;
}
//int find(int x)//查
//{
// if(x!=pe[x].pre)
// {
// pe[x].pre=find(pe[x].pre);
// }//回溯
// return pe[x].pre;
//}
void init()
{
for(int i=0;i>n)
{
init();
int max=-1;
for(i=1;i<=n;i++)
{
cin>>a>>b;
int f1=find(a);
int f2=find(b);
if(f1!=f2)
{
pe[f2].pre=f1;
pe[f1].num+=pe[f2].num;
}
/* if(pe[f1].num>max)//为什么不能这样求最大值,还是搞不懂
max=pe[f1].num;*/
}
for(i=1;imax)
max=pe[i].num;
}
cout< ;i++)> ;i++)>
相关文章: