标签:
1 const maxn=100; 2 var 3 i,j,k,l,m,n:longint; 4 c:array[0..maxn] of longint; 5 function getfat(x:longint):longint; \\非路径压缩 6 begin 7 if c[x]<>x then exit(getfat(c[x])) else exit(x); 8 end; 9 { 10 function getfat(x:longint):longint; \\路径压缩 11 begin 12 if c[x]<>x then c[x]:=getfat(x); 13 exit(c[x]); 14 end; 15 } 16 begin 17 readln(n,m); 18 for i:=1 to n do c[i]:=i; 19 for i:=1 to m do 20 begin 21 readln(l,j,k); 22 case l of 23 1:c[getfat(j)]:=getfat(k); \\merge 24 2:writeln(getfat(j)=getfat(k)); \\query 25 end; 26 end; 27 end.
标签:
原文地址:http://www.cnblogs.com/Fefnir/p/5592919.html