function getfather(v:longint):longint;//寻找根节点 begin if father[v]=v then exit(v); father[v]:=getfather(father[v]); exit(father[v]); end;
procedure merge(x,y:longint);//合并两集合 var xx,yy:longint; begin xx:=getfather(x); yy:=getfather(y); father[xx]:=yy; end;
function judge(x,y:longint):boolean;//判断是否在一集合中 var xx,yy:longint; begin xx:=getfather(x); yy:=getfather(y); exit(xx=yy); end;