Pagini recente » Cod sursa (job #4952) | Cod sursa (job #573261) | Cod sursa (job #1147095) | Cod sursa (job #375534) | Cod sursa (job #1623814)
program disj;
var f, g:text;
v:array of longint;
bufin, bufout:array[1..1 shl 16] of byte;
n, m, i, cod, x, y:longint;
function find(nod:longint):longint;
begin
while v[nod] > 0 do nod := v[nod];
find := nod;
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(v, n + 2);
for i := 1 to m do
begin
readln(f, cod, x, y);
if cod = 1 then
v[find(y)] := find(x)
else
begin
if find(x) = find(y) then writeln(g, 'DA')
else writeln(g, 'NU');
end;
end;
close(f); close(g);
end.