//并查集模板 

int n, m, pre[N*2], vis[N*2];

void init(){
	for(int i = 1; i <= n; ++i)
		pre[i] = i;
}
int find(int x){
	if(x != pre[x]) pre[x] = find(pre[x]);
	return pre[x];
}
void link(int x, int y){
	int rtx = find(x), rty = find(y);
	if(rtx != rty) pre[rty] = rtx;
}