struct Loc
{
int x,y;
}loc[55][55],pre[55][55];
Loc Union_find(Loc root)
{
Loc son=pre[root.x][root.y];Loc t;
while(root.x!=pre[root.x][root.y].x || root.y!=pre[root.x][root.y].y)
root=pre[root.x][root.y];
while(son.x!=root.x || son.y!=root.y)
{
t=pre[son.x][son.y];
pre[son.x][son.y]=root;
son=t;
}
return root;
}
void Union(Loc x,Loc y)
{
Loc a=Union_find(x);
Loc b=Union_find(y);
if(a.x==b.x && a.y==b.y) return;
pre[a.x][a.y]=b;
}