BZOJ3563 : DZY Loves Chinese

时间:2021-08-07 09:09:28

想法题,由于K是加密的,但是通过读入我们可以自己数出来这一行有几个数,

所以可以直接反解出之前回答为连通的个数

至于最后一个询问就用并查集暴力回答

var
n,i,m,s,k,j,q : longint;
u,v,cnt,f : array[0..500000] of longint;
c : array[1..15] of longint;
del : array[1..500000] of boolean;
function fa(x : longint) : longint;
begin
if f[x] = x then exit(x);
f[x] := fa(f[x]);
exit(f[x]);
end;
begin
readln(n,m);
for i := 1 to m do readln(u[i],v[i]);
readln(q);
for i := 1 to q do
begin
read(s);
k := 0;
while not eoln do
begin
inc(k);
read(c[k]);
end;
cnt[i-1] := k xor s;
readln;
end;
for i := 1 to q-1 do
if cnt[i] = cnt[i-1] then
writeln('Disconnected')
else
writeln('Connected');
for i := 1 to k do del[c[i] xor cnt[q-1]] := true;
for i := 1 to n do f[i] := i;
for i := 1 to m do
if not del[i] then
if fa(u[i]) <> fa(v[i]) then
begin
f[f[u[i]]] := f[v[i]];
dec(n);
end;
if n > 1 then
writeln('Disconnected')
else
writeln('Connected');
end.