Pagini recente » Cod sursa (job #1029316) | Cod sursa (job #32168) | Cod sursa (job #1184753) | Cod sursa (job #2179894) | Cod sursa (job #822561)
Cod sursa(job #822561)
Program p1;
var fi,fo:text; b1,b2:array[0..1 shl 20] of char;
tata,rang,oper:array[0..100005] of longint;
i,n,m,oper1,x,y:longint;
Function radacina(x:longint):longint;
var aux,q:longint;
begin
q:=x;
while tata[q]<>q do q:=tata[q];
radacina:=q;
end;
Procedure uneste(x,y:longint);
begin
if rang[x]>rang[y] then tata[y]:=x
else tata[x]:=y;
if rang[x]=rang[y] then inc(rang[y]);
end;
begin
assign(fi,'disjoint.in'); reset(fi);
assign(fo,'disjoint.out'); rewrite(fo);
settextbuf(fi,b1); settextbuf(fo,b2);
readln(fi,n,m);
for i:=1 to n do begin
tata[i]:=i;
rang[i]:=1;
end;
for i:=1 to m do begin
readln(fi,oper1,x,y);
if oper1=1 then uneste(radacina(x),radacina(y))
else begin
if radacina(x)=radacina(y) then writeln(fo,'DA')
else writeln(fo,'NU');
end;
end;
close(fi); close(fo);
end.