【数据结构】Union-find

 1 var
 2    father:array[1..10000] of integer;
 3    n,i:integer;
 4 function getfather(a:integer):integer;
 5 begin
 6   if father[a]=0 then exit(0);
 7   father[a]:=getfather(father[a]);
 8   getfather:=father[a];
 9 end;
10 function judge_union(a,b:integer):boolean;
11 var
12    fa,fb:integer;
13 begin
14    fa:=father[a];
15    fb:=father[b];
16    if fa=fb then exit(true);
17    father[fa]:=fb;
18    exit(false);
19 end;

 

posted @ 2013-08-13 18:38  OmegaIota  阅读(268)  评论(0编辑  收藏  举报