Pagini recente » Cod sursa (job #3274953) | Cod sursa (job #2496804) | Cod sursa (job #1775472) | Cod sursa (job #1879259) | Cod sursa (job #291427)
Cod sursa(job #291427)
program suma;
const fin = 'disjoint.in';
fout = 'disjoint.out';
var m:array [1..100000] of longint;
n,x,y,op,i:longint;
procedure join(x,y:integer);
var t1,t2:integer;
begin
t1:=m[y];
t2:=m[x];
for i:=1 to n do
if m[i]=t1 then
m[i]:=t2;
end;
procedure query(x,y:integer);
begin
if m[x] = m[y] then
writeln('DA')
else
writeln('NU');
end;
begin
assign(input,fin);
assign(output,fout);
reset(input);
rewrite(output);
read(n);
for i:=1 to n do
m[i]:=i;
readln(x);
while not eof() do
begin
readln(op,x,y);
if op = 1 then
join(x,y)
else
query(x,y);
end;
close(input);
close(output);
end.