BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
来源:互联网 发布:windows清理助手64 编辑:程序博客网 时间:2024/06/05 03:01
题目大意:给出一张n个点m条边的无向图。进行q次询问,问删掉某k条边后图是否联通。强制在线
N≤100000 M≤500000 Q≤50000 1≤K≤15
这题好神啊…
首先找出图中的一棵生成树,对于每一条非树边赋上一个随机值,每条树边等于覆盖它的非树边的权值的异或和,那么这个图不连通当存在一个删掉的边的子集的异或和为0。
线性基搞一下看能不能异或出0。
#include <cstdio>#include <algorithm>#include <cstring>#define N 100005using namespace std;int RAND() { return (rand()<<16)+rand(); }struct Edge { int to,nxt; Edge() {} Edge(int _to,int _nxt):to(_to),nxt(_nxt) {}}e[N*10];int n,m,T,tot=1,top,ans,s[20],fir[N],val[N*5],p[N];bool vis[N];void Add_Edge(int u,int v) { e[++tot]=Edge(v,fir[u]), fir[u]=tot; e[++tot]=Edge(u,fir[v]), fir[v]=tot; return ;}void dfs1(int x,int from) { vis[x]=true; for(int i=fir[x];~i;i=e[i].nxt) { if(e[i].to==from) continue; if(!vis[e[i].to]) dfs1(e[i].to,x); else if(!val[i/2]) { int rd=RAND(); val[i/2]=rd; p[x]^=rd; p[e[i].to]^=rd; } } return ;}void dfs2(int x,int from) { vis[x]=true; for(int i=fir[x];~i;i=e[i].nxt) { if(vis[e[i].to]) continue; dfs2(e[i].to,x); val[i/2]=p[e[i].to]; p[x]^=p[e[i].to]; } return ;}void Gauss() { int j=0; for(int k=30;~k;--k) { int i; for(i=j+1;i<=top;++i) if(s[i]&(1<<k)) break; if(i==top+1) continue; swap(s[i],s[++j]); for(int i=1;i<=top;++i) if(s[i]&(1<<k) && i!=j) s[i]^=s[j]; } return ;}int main() { memset(fir,-1,sizeof fir); scanf("%d%d",&n,&m); for(int i=1,x,y;i<=m;++i) scanf("%d%d",&x,&y), Add_Edge(x,y); dfs1(1,0); memset(vis,false,sizeof vis); dfs2(1,0); for(scanf("%d",&T);T;--T) { scanf("%d",&top); for(int i=1;i<=top;++i) scanf("%d",s+i), s[i]=val[s[i]^ans]; Gauss(); if(s[top]) ++ans; puts(s[top] ? "Connected" : "Disconnected"); } return 0;}
阅读全文
0 0
- BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
- bzoj 3569: DZY Loves Chinese II (线性基)
- BZOJ 3569: DZY Loves Chinese II 线性基 随机化
- BZOJ 3569 DZY Loves Chinese II(线性基)
- BZOJ 3563 DZY Loves Chinese / BZOJ 3569 DZY Loves Chinese II 随机化+高斯消元解异或方程组
- BZOJ 3569 DZY Loves Chinese II 高斯消元
- bzoj 3569: DZY Loves Chinese II
- BZOJ 3569: DZY Loves Chinese II
- BZOJ 3563 DZY Loves Chinese(线性基)
- [高斯消元 线性基 生成树 随机化权值Xor] BZOJ 3569 DZY Loves Chinese II
- bzoj 3569: DZY Loves Chinese II dfs树+线性基【神题】
- [bzoj 3563&3569]DZY Loves Chinese I&II
- 3237: [Ahoi2013]连通图/3563: DZY Loves Chinese/3569: DZY Loves Chinese II 线性基+随机化
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- BZOJ 3563 DZY Loves Chinese 并查集
- [乱搞 暴力 并查集] BZOJ 3563 DZY Loves Chinese
- Eslint规则
- shiro多登录入口,多realm认证
- Leetcode 373 Find K Pairs with Smallest Sums
- PAT 1012. 数字分类 (20) —— Java(未满分)
- 机器学习002—决策树
- BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
- Drawable学习之---NinePatchDrawable(.9图片的制作)
- suse linux 系统下安装tomcat
- AJAX 执行顺序讨论之JavaScript权威指南第6版
- vue一.模板语法
- java中final修饰词的使用
- 如何成为牛逼的程序员
- React.js 官网资料摘记:使用Prop-Types检查类型
- 面向接口编程详解(一)——思想基础