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
- bzoj 3563 ╮(╯▽╰)╭+ 并查集
- BZOJ 1202 并查集
- BZOJ 1015 并查集
- BZOJ 1854 并查集
- BZOJ 1015 并查集
- bzoj 1529 并查集
- BZOJ 1116 并查集
- bzoj 1116 并查集
- bzoj 1854 并查集
- bzoj 2054 并查集
- bzoj 1050 并查集
- BZOJ 3563 DZY Loves Chinese 并查集
- [乱搞 暴力 并查集] BZOJ 3563 DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese 并查集+乱搞
- 【并查集】【bzoj 1116】: [POI2008]CLO
- BZOJ 2079 Poi2010 Guilds 并查集
- BZOJ 3454 家族 并查集
- BZOJ 1116 POI2008 CLO 并查集
- android bitmap 缓存 处理
- 网管的自我修养-外设相关
- 企业号认证接口
- logstash 时间处理
- BZOJ 1098: [POI2007]办公楼biu 补图联通块个数,链表优化
- bzoj 3563 ╮(╯▽╰)╭+ 并查集
- 微信小程序之MaterialDesign(三)-- SnackBar
- 苹果
- C++ 输入与输出
- cmd中Telnet 127.0.0.1 8080 什么时候能够正常建立连接呢?
- 设计-架构资料
- 夕拾算法进阶篇:18)装箱问题 (01背包_动态规划DP)
- NLP技能需求
- logstash 贪婪匹配