Pagini recente » Cod sursa (job #1576618) | Istoria paginii utilizator/domanitos | Cod sursa (job #2110192) | Cod sursa (job #2969239) | Cod sursa (job #408764)
Cod sursa(job #408764)
{$Inline on}
const tfi='disjoint.in';
tfo='disjoint.out';
maxn=100002;
var fi,fo:text;
m,n:longint;
lab:array[0..maxn] of longint;
function getroof(u:longint):longint; inline;
var v:longint;
begin
// v:=u;
while lab[u]>0 do u:=lab[u];
// lab[v]:=u;
exit(u);
end;
procedure union(u,v:Longint); inline;
var x:longint;
begin
x:=lab[u]+lab[v];
if lab[u]>lab[v] then
begin
lab[u]:=v;
lab[v]:=x;
end
else
begin
lab[v]:=u;
lab[u]:=x;
end;
end;
procedure process;
var ii,jj,i,j,u,v:longint;
begin
fillchar(lab,sizeof(lab),255);
read(fi,n,m);
for i:=1 to m do
begin
read(fi,j,u,v);
ii:=getroof(u);
jj:=getroof(v);
if j=1 then
if ii<>jj then union(ii,jj) else
else
if ii=jj then writeln(fo,'DA') else writeln(fo,'NU');
end;
end;
begin
assign(fi,tfi); reset(fi);
assign(Fo,tfo); rewrite(fo);
process;
close(fi); close(fo);
end.