WZTong @ 2016-10-05 09:41:35
var b:array[1..1000000]of integer;m,n,i,j,x,y,z:integer;
function gjd(x:integer):integer;
begin
if b[x]=x then exit(x);
b[x]:=gjd(b[x]);
gjd:=b[x];
end;
procedure hb(x,y:integer);
begin
x:=gjd(x);
y:=gjd(y);
b[x]:=y;
end;
procedure sc(x,y:integer);
begin
if gjd(x)=gjd(y) then writeln('Y') else writeln('N');
end;
begin
readln(n,m);
for i:=1 to n do
b[i]:=i;
for i:=1 to m do
begin
read(z,x,y);
if z=1 then hb(x,y);
if z=2 then sc(x,y);
end;
end.
by 不可喵的 @ 2016-10-05 10:06:31
m<=200000 ! integer个鬼啊。
by 别有根芽 @ 2016-11-10 21:42:56
最后三个是大数据,用longint!