BZOJ 3563 DZY Loves Chinese(线性基)
来源:互联网 发布:网络用语ps是什么意思 编辑:程序博客网 时间:2024/05/29 14:31
Description
神校
摄提贞于孟陬兮,惟庚寅
纷
遂降临于
今
时而
而后俟其日
然若有祭坛无法相互到达,
Input
第一行
接下来
接下来一行
接下来
每行第一个数
为了体现在线,
数据保证没有重边与自环
Output
对于每个询问输出:连通则为
Sample Input
4 5
1 2
2 3
3 4
4 1
2 4
3
1 5
2 2 3
2 1 2
Sample Output
Connected
Disconnected
Connected
Solution
先找到原图的一个生成树,给非树边随机边权,定义点权为以其为端点的非树边边权异或和,给树定向之后,树边的权值为其深度较深的端点点权,这样如果删去的边集中存在一个子集使得其权值异或和为
Code
#include<cstdio>#include<cstring>#include<algorithm>#include<ctime>using namespace std;namespace fastIO { #define BUF_SIZE 100000 //fread -> read bool IOerror=0; inline char nc() { static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; if(p1==pend) { p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); if(pend==p1) { IOerror=1; return -1; } } return *p1++; } inline bool blank(char ch) { return ch==' '||ch=='\n'||ch=='\r'||ch=='\t'; } inline void read(int &x) { char ch; while(blank(ch=nc())); if(IOerror)return; for(x=ch-'0';(ch=nc())>='0'&&ch<='9';x=x*10+ch-'0'); } #undef BUF_SIZE};using namespace fastIO;const int maxn=100005,maxm=500005;struct node{ int v,next;}edge[maxm*2];int n,m,q,res,vis[maxn],val[maxn],weight[maxm],tot,head[maxn],base[33];void add(int u,int v){ edge[++tot].v=v,edge[tot].next=head[u],head[u]=tot;}void dfs(int u,int fa){ vis[u]=res++; for(int i=head[u];i;i=edge[i].next) { int v=edge[i].v; if(v==fa)continue; if(!vis[v]) { dfs(v,u); weight[i/2]=val[v]; val[u]^=val[v]; } else if(vis[u]>vis[v]) { weight[i/2]=rand()+1; val[u]^=weight[i/2]; val[v]^=weight[i/2]; } }}int main(){ srand(19971109); read(n);read(m);//scanf("%d%d",&n,&m); tot=res=1; while(m--) { int u,v; read(u);read(v);//scanf("%d%d",&u,&v); add(u,v),add(v,u); } dfs(1,0); int num=0; read(q);//scanf("%d",&q); while(q--) { int k,temp,flag=0; read(k);//scanf("%d",&k); k^=num; memset(base,0,sizeof(base)); while(k--) { read(temp);//scanf("%d",&temp); temp=weight[temp^num]; for(int i=30;i>=0;i--) if(temp>>i&1) { if(!base[i]) { base[i]=temp; break; } else temp^=base[i]; } if(!temp)flag=1; } if(flag)printf("Disconnected\n"); else printf("Connected\n"),num++; } return 0;}
阅读全文
0 0
- BZOJ 3563 DZY Loves Chinese(线性基)
- BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
- bzoj 3569: DZY Loves Chinese II (线性基)
- BZOJ 3569 DZY Loves Chinese II(线性基)
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese
- BZOJ 3569: DZY Loves Chinese II 线性基 随机化
- 3237: [Ahoi2013]连通图/3563: DZY Loves Chinese/3569: DZY Loves Chinese II 线性基+随机化
- BZOJ 3563 DZY Loves Chinese / BZOJ 3569 DZY Loves Chinese II 随机化+高斯消元解异或方程组
- [高斯消元 线性基 生成树 随机化权值Xor] BZOJ 3569 DZY Loves Chinese II
- bzoj 3569: DZY Loves Chinese II dfs树+线性基【神题】
- 【bzoj3569】DZY Loves Chinese II 线性基+树上小技巧
- [BZOJ3569]DZY Loves Chinese II 哈希+线性基
- BZOJ 3563 DZY Loves Chinese 并查集
- [bzoj 3563&3569]DZY Loves Chinese I&II
- [乱搞 暴力 并查集] BZOJ 3563 DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese 并查集+乱搞
- unity5 manifest
- springboot +druid性能检测
- 实现浏览器点击后退键刷新界面
- Rancher Pipeline发布:开源、极简、强大的CI/CD
- 产品测试规范(三)
- BZOJ 3563 DZY Loves Chinese(线性基)
- WebService实例-CRM系统提供WebService实现用户注册功能
- MySQL表的约束及外键的添加
- JSTL格式化标签与函数
- 130. Surrounded Regions
- 依依东望
- ActionScript Object 2 Java Object
- bazel使用问题汇总
- 简单的图片上传功能