标签:mem 暴力 记录 fine std ace 生成 disco ==
#include<bits/stdc++.h>
#define R register int
#define ll long long
#define uLL unsigned long long
using namespace std;
const int N=2000001;
const int M=1000001;
int n,m,cnt,vis[N],nt[M],to[M],hd[N],p,flag;
uLL num[M],vl[N],Bas[35];
struct ed{int u,v,us;}G[M];
void link(R f,R t){nt[++cnt]=hd[f],to[cnt]=t,hd[f]=cnt;}
uLL rnd() { return (((uLL)rand())<<32)^((uLL)rand()<<16)^rand(); }
int gi(){
R x=0,k=1;char c=getchar();
while((c<‘0‘||c>‘9‘)&&c!=‘-‘)c=getchar();
if(c==‘-‘)k=-1,c=getchar();
while(c>=‘0‘&&c<=‘9‘)x=(x<<3)+(x<<1)+c-‘0‘,c=getchar();
return x*k;
}
void Dfs1(R i,R e){
vis[i]=1;
for(R k=hd[i];k;k=nt[k])
if(!vis[to[k]])
G[k>>1].us=1,Dfs1(to[k],i);
}
void Dfs2(R i){
vis[i]=1;
for(R k=hd[i];k;k=nt[k])
if(!vis[to[k]]){
Dfs2(to[k]),vl[k>>1]=num[to[k]];
num[i]^=num[to[k]];
}
}
void ins(R x){
for(R j=0;j<=30;++j){
(!x)?flag=1:0;
if((1<<j)&x){
if(!Bas[j]){Bas[j]=x;return;}
else x^=Bas[j];
}
}
}
int main(){
freopen("chi.in","r",stdin);
freopen("chi.out","w",stdout);
srand(time(NULL));
n=gi(),m=gi(),cnt=1;
for(R i=1;i<=m;++i){
G[i].u=gi(),G[i].v=gi();
link(G[i].u,G[i].v),link(G[i].v,G[i].u);
}
Dfs1(1,0);
for(R i=1;i<=m;++i)
if(!G[i].us){
vl[i]=rnd();
num[G[i].u]^=vl[i],num[G[i].v]^=vl[i];
}
memset(vis,0,sizeof(vis));
Dfs2(1);R u=0,q=gi(),v;
while(q--){
p=gi(),flag=0,memset(Bas,0,sizeof(Bas));
for(R j=1;j<=p;++j)v=gi()^u,ins(vl[v]);
if(!flag)u++,puts("Connected");
else puts("Disconnected");
}
return 0;
}
bzoj 3569: DZY Loves Chinese II
标签:mem 暴力 记录 fine std ace 生成 disco ==
原文地址:https://www.cnblogs.com/Tyher/p/9827421.html