Pagini recente » Cod sursa (job #1339912) | Cod sursa (job #2376584) | Cod sursa (job #1402570) | Cod sursa (job #2417712) | Cod sursa (job #1622247)
program disj;
var f,g:text;
n,i,x,y,z,m:longint;
marcaj:array of longint;
bufin,bufout:array [1..1 shl 17] of char;
procedure inserare(y,z:longint);
var j:longint;
begin
for j:=1 to n do
if marcaj[j]=marcaj[y] then
marcaj[j]:=marcaj[z];
end;
begin
assign(f,'disjoint.in');reset(f);
assign(g,'disjoint.out');rewrite(g);
settextbuf(f,bufin);settextbuf(g,bufout);
readln(f,n,m);
setlength(marcaj,n+1);
for i:=1 to n do
marcaj[i]:=i;
for i:=1 to m do
begin
readln(f,x,y,z);
if x=1 then
inserare(y,z)
else
if marcaj[y]=marcaj[z] then
writeln(g,'DA')
else
writeln(g,'NU');
end;
close(f);
close(g);
end.