三倍经验…
这个给边随机化我似乎在那里见过?
…大概就是给边分为树边和非树边,非树边的值是随机的,树边的边是子树的非树边的异或和
然后线性基搞一搞就好了
c++代码如下:
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x ;i <= y; ++ i)
#define repd(i,x,y) for(register int i = x ;i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
char c;int sign = 1;x = 0;
do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
x *= sign;
}
const int N = 1e5+50,M = 1e6+50;
int head[N],nxt[M],to[M],tot;
int n,m;
inline void add(int x,int y)
{
to[tot] = y;
nxt[tot] = head[x];
head[x] = tot++;
}
int vis[N],sz;
int a[M],b[M];
void dfs(int x,int f)
{
vis[x] = ++ sz;
for(register int i = head[x];~i;i=nxt[i])
if(to[i] != f)
{
if(!vis[to[i]])
{
dfs(to[i],x);
a[i>>1] = b[to[i]];
b[x] ^= b[to[i]];
}
else if(vis[to[i]] < vis[x])
{
a[i>>1] = rand();
b[x] ^= a[i>>1];
b[to[i]]^=a[i>>1];
}
}
}
int J[40];
int main()
{
srand(time(NULL));
memset(head,-1,sizeof head); tot = 2;
read(n); read(m);
rep(i,1,m)
{
int u,v;
read(u); read(v);
add(u,v); add(v,u);
}
dfs(1,1);
int q,c,x,z = 0; read(q);
rep(e,1,q)
{
read(c);c ^= z;
bool op = 1;
memset(J,0,sizeof J);
rep(j,1,c)
{
read(x);
int w = a[x^z];
rep(i,0,31)
if(w >> i&1)
{
if(J[i]) w ^= J[i];
else
{
J[i] = w;
break;
}
}
if(!w) op = 0;
}
z += op;
puts(op?"Connected":"Disconnected");
}
return 0;
}