BZOJ 3569: DZY Loves Chinese II 线性基 随机化
2017-11-27 15:50
363 查看
3569: DZY Loves Chinese II
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 986 Solved: 381
[Submit][Status][Discuss]
Description
神校XJ之学霸兮,Dzy皇考曰JC。摄提贞于孟陬兮,惟庚寅Dzy以降。
纷Dzy既有此内美兮,又重之以修能。
遂降临于OI界,欲以神力而凌♂辱众生。
今Dzy有一魞歄图,其上有N座祭坛,又有M条膴蠁边。
时而Dzy狂WA而怒发冲冠,神力外溢,遂有K条膴蠁边灰飞烟灭。
而后俟其日A50题则又令其复原。(可视为立即复原)
然若有祭坛无法相互到达,Dzy之神力便会大减,于是欲知其是否连通。
Input
第一行N,M接下来M行x,y:表示M条膴蠁边,依次编号
接下来一行Q
接下来Q行:
每行第一个数K而后K个编号c1~cK:表示K条边,编号为c1~cK
为了体现在线,c1~cK均需异或之前回答为连通的个数
Output
对于每个询问输出:连通则为‘Connected’,不连通则为‘Disconnected’(不加引号)
Sample Input
5 102 1
3 2
4 2
5 1
5 3
4 1
4 3
5 2
3 1
5 4
5
1 1
3 7 0 3
4 0 7 4 6
2 2 7
4 5 0 2 13
Sample Output
ConnectedConnected
Connected
Connected
Disconnected
HINT
N≤100000 M≤500000 Q≤50000 1≤K≤15数据保证没有重边与自环
Tip:请学会使用搜索引擎
http://blog.csdn.net/Phenix_2015/article/details/50931445
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>10)print(x/10);putchar(x%10+'0');}
const int N=100100;
const int M=1001000;
int last
,ecnt=1;
struct EDGE{int to,nt;}e[M<<1];
inline void add(int u,int v)
{e[++ecnt]=(EDGE){v,last[u]};last[u]=ecnt;}
int ins[40];
int a[M],b
;
int dfn
,tim;
void dfs(int u,int fa)
{
dfn[u]=++tim;
for(int i=last[u],v;i;i=e[i].nt)
if(e[i].to!=fa)
{
v=e[i].to;
if(!dfn[v])
{
dfs(v,u);
b[u]^=b[v];
a[i>>1]=b[v];
}
else if(dfn[v]<dfn[u])
{
a[i>>1]=rand();
b[u]^=a[i>>1];
b[v]^=a[i>>1];
}
}
}
int main()
{
srand(19260817);
int n=read(),m=read();
register int i,j,K,x,u,v,tot(0);
for(i=1;i<=m;++i)
{
u=read();v=read();
add(u,v);add(v,u);
}
dfs(1,0);
register int Q=read();
register bool flag;
while(Q--)
{
K=read();flag=1;
memset(ins,0,sizeof(ins));
for(i=1;i<=K;++i)
{
x=a[read()];
for(j=30;~j;j--)
if((x>>j)&1)
{
if(!ins[j])
{
ins[j]=x;
break;
}
else x^=ins[j];
}
if(!x)flag=0;
}
tot+=flag;
flag?puts("Connected"):puts("Disconnected");
}
return 0;
}
相关文章推荐
- BZOJ 3569 DZY Loves Chinese(BZOJ 3563) II 线性基
- BZOJ 3569 DZY Loves Chinese II(线性基)
- 【BZOJ 3569】DZY Loves Chinese II 随机化+线性基
- BZOJ3569 DZY Loves Chinese II(随机化+树上差分+线性基)
- bzoj 3569: DZY Loves Chinese II (线性基)
- BZOJ 3569 DZY Loves Chinese II ——线性基
- [BZOJ3569]DZY Loves Chinese II(随机化+线性基)
- bzoj3569: DZY Loves Chinese II【线性基】
- BZOJ3569 : DZY Loves Chinese II
- 【bzoj3569】 DZY Loves Chinese II
- BZOJ 3569: DZY Loves Chinese II
- BZOJ3569: 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 3569 DZY Loves Chinese II 随机化+高斯消元解异或方程组
- BZOJ 3569 DZY Loves Chinese II
- BZOJ3569 DZY Loves Chinese II
- 【BZOJ 3569】 DZY Loves Chinese II
- BZOJ 3569: DZY Loves Chinese II [高斯消元XOR 神题]