bzoj 3563 ╮(╯▽╰)╭+ 并查集

来源:互联网 发布:软件开发计划书 编辑:程序博客网 时间:2024/05/01 21:09

题意:N个点,M条无向边,Q个操作,每个操作中破坏K条边,其中编号和K已经加密,即原数异或之前未联通的个数(给的是原k,但后面有异或后的k的个数个编号),判断每个操作后是否联通

会做题不等于会出题系列..... ╮(╯▽╰)╭

虽然k已经加密,但是由于k后面跟着k个编号,我们依旧能知道加密后的k╮(╯▽╰)╭

由于一个数异或两次相当于没有异或,所以我们很容易就得到了之前未联通的个数╮(╯▽╰)╭

令 c[i]=segma(1~i-1未联通的个数和)

当 c[i] != c[i-1] 时,第(i-1)个操作是联通的,否则是不连通的

于是我们就判断出了1~q-1 操作后的连通性  ╮(╯▽╰)╭

对于第q个操作,暴力并查集维护即可╮(╯▽╰)╭

var        n,m,t,tx,ty,q,k,p:longint;        i                :longint;        c,cnt            :array[0..50010] of longint;        f                :array[0..100010] of longint;        flag             :array[0..500010] of boolean;        x,y              :array[0..500010] of longint;function get_father(x:longint):longint;begin   if x=f[x] then exit(x);   f[x]:=get_father(f[x]);   exit(f[x]);end;begin   read(n,m);   for i:=1 to n do f[i]:=i;   for i:=1 to m do read(x[i],y[i]);   read(q);   for i:=1 to q do   begin      read(k);      t:=0;      while not eoln do      begin         read(p);         inc(t);         cnt[t]:=p;      end;      c[i]:=t xor k;   end;   //   for i:=2 to q do     if (c[i]=c[i-1]) then writeln('Disconnected') else writeln('Connected');   //   for i:=1 to t do flag[cnt[i] xor c[q]]:=true;   t:=0;   for i:=1 to m do     if not flag[i] then     begin        tx:=get_father(x[i]);        ty:=get_father(y[i]);        if (tx<>ty) then        begin           f[ty]:=tx;           inc(t);           if t=n-1 then           begin              writeln('Connected');exit;           end;        end;     end;   writeln('Disconnected');end.
——by Eirlys




0 0
原创粉丝点击