BZOJ 3569: DZY Loves Chinese II
来源:互联网 发布:翻译机 知乎 编辑:程序博客网 时间:2024/06/05 04:00
一开始看到这道题的时候 简直懵逼
(我是摸着线性基这个标签来的
然后去膜题解。。what?还有这种操作。。
神题啊QAQ
给一篇不错的题解 (没错 我抄参考了他的代码 因为写的挺不错的。。)
upd: 讲道理我也是觉得这个做法是需要一个证明的 于是去找了董先生QAQ
Orz董先生 董先生写了个正确性证明 大家可以去看看
为什么会WA呢 因为据说是有错误率的。。。
所以你可以把随机数范围弄到LL 或者 你想卡过去的话 换多几个时间种子吧。。 所以说 3237也可以用这种做法过 嘿嘿嘿
#include<bits/stdc++.h>#define me(a,x) memset(a,x,sizeof a)using namespace std;const int N=1e5+2;char B[1<<14],*S=B,*T=B;#define gc (S==T&&(T=(S=B)+fread(B,1,1<<14,stdin),S==T)?-1:*S++)inline int read(){ int x=0,f=1; char ch=gc; while(ch<'0' || ch>'9'){if(ch=='-')f=-1; ch=gc;} while(ch>='0' && ch<='9'){x=(x<<1)+(x<<3)+ch-'0'; ch=gc;} return x*f;}struct edge{int x,y,nex;}a[N*10]; int len,fir[N];void ins(int x,int y){ a[++len]=(edge){x,y,fir[x]},fir[x]=len;}bool v[N]; int num[N*10],c[N],p[32];void dfs(int x,int fa){ v[x]=1; for(int k=fir[x];k;k=a[k].nex){ int y=a[k].y; if(y==fa)continue; if(!v[y])dfs(y,x); else num[k>>1]=rand(); }}void sol(int x,int fa){ v[x]=1; for(int k=fir[x];k;k=a[k].nex){ int y=a[k].y; if(y==fa || v[y])continue; sol(y,x); c[x]^=c[y],num[k>>1]=c[y]; }}int main(){ srand(77821594); len=1; int n=read(),m=read(),i; for(i=1;i<=m;++i){ int x=read(),y=read(); ins(x,y),ins(y,x); } dfs(1,0); for(i=1;i<=m;++i) c[a[i<<1].x]^=num[i],c[a[i<<1].y]^=num[i]; me(v,0); sol(1,0); int q=read(),cnt=0; while(q--){ int k=read(); me(p,0); bool ok=1; for(i=1;i<=k;++i){ int x=read()^cnt; x=num[x]; for(int j=31;~j;--j) if(x>>j&1){ if(!p[j]){p[j]=x; break;} else x^=p[j]; } if(!x)ok=0; } if(ok)puts("Connected"),++cnt; else puts("Disconnected"); } return 0;}
阅读全文
1 0
- 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(BZOJ 3563) II 线性基
- [bzoj 3563&3569]DZY Loves Chinese I&II
- bzoj 3569: DZY Loves Chinese II (线性基)
- BZOJ 3569: DZY Loves Chinese II 线性基 随机化
- BZOJ 3569 DZY Loves Chinese II(线性基)
- BZOJ3563/3569 DZY Loves Chinese II/DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj3569 DZY Loves Chinese II
- [高斯消元 线性基 生成树 随机化权值Xor] BZOJ 3569 DZY Loves Chinese II
- bzoj 3569: DZY Loves Chinese II dfs树+线性基【神题】
- 3237: [Ahoi2013]连通图/3563: DZY Loves Chinese/3569: DZY Loves Chinese II 线性基+随机化
- BZOJ 3563 DZY Loves Chinese 并查集
- Android面试
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession dp
- 解决Android studio开发找不到HttpClient问题
- linux学习之基本命令
- 关于如何写好简历的指北
- BZOJ 3569: DZY Loves Chinese II
- 一 Javaweb 项目中常见的思想、思路从哪去、原则 反思回顾:
- vue项目的搭建
- 超时代码 01 matrix
- 一起来学SQL(二)
- 第四周项目 ONE---建立单链表
- HBuilder快捷键
- kd tree python 搜索
- js动画旋转与缩放