#include<iostream>
using namespace std;
#define MAX 10000
int p[MAX];
int rank[MAX];
int n;
int Init()
{
int i;
for(i=1;i<=n;i++)
{
p[i]=i;
rank[i]=0;
}
return 0;
}
int Find(int x)
{
if(p[x]!=x)
{
p[x]=Find(p[x]);
}
return p[x];
}
int Union(int x,int y)
{
int a=Find(x);
int b=Find(y);
if(rank[a]>rank[b])
{
p[b]=a;
}
else
{
if(rank[b]==rank[a])
{
rank[b]++;
}
p[a]=b;
}
return 0;
}