int find( int x )
{
return x != p[x]?p[x] = find(p[x]):x;
}
void merge( int a,int b )
{
int x = find(a);
int y = find(b);
if( rank[x] > rank[y] )
{
p[y] = x;
}
else
{
p[x] = y;
if( rank[x] == rank[y] )
rank[y]++;
}
}