var
father:array[1..maxn] of longint;
procedure init;
var
i:longint;
begin
for i:=1 to maxn do father[i]:=-1;
end;
function f(x:longint):longint;
begin
if father[x]=-1 then exit(x)
else begin
father[x]:=f(father[x]);
exit(father[x]);
end;
end;
procedure union(a,b:longint);
begin
if f(a)<f(b) then
father[f(a)]:=f(b);
end;
function same(a,b:longint):boolen;
begin
if f(a)=f(b) then exit(true) else exit(false);
end;
并查集模版
最新推荐文章于 2021-12-15 00:30:14 发布