题面在这里!

这两个其实是一个题啦。。双倍经验加成23333

可以很简单的发现如果把一条树边和所有覆盖它的非树边都删去的话,那么图会不连通;

如果再手玩一下可以发现,如果把两个被非树边覆盖的集合相同的树边删去,图也是会不连通的。

于是大胆猜想一波,我们给每条边附上一个非树边集合,里面的边就是它被哪些非树边覆盖,特殊的如果这条边本来就是非树边那么这个集合里只有它一个。。。

只有询问中删去的边的集合存在至少一个子集,满足里面所有边的非树边集合的异或为空(应该说对称差?),那么图不连通。

显然bitset可以保证正确性,但是太慢了会GG掉。。。

于是我们可以延用某oj某月的月赛的一道叫对称数的题的套路,给每条非树边随机一个 < 2^64 的边权,然后集合的权值可以表示成集合内所有非树边边权的异或,于是集合异或为空就相当于要所有集合的权值的异或和为0,线性基判一判就好啦。

如果想让这个算法出现偏差,那么当且仅当 存在一个非树边的集合 使得集合的权值为0。

也就是二进制每一位都是0,那么这个概率显然是 1/2^64  (注意这个集合大小无关,因为杨辉三角同一行的奇数列的和永远是总和的1/2 (第0行除外))。

并且就算存在了,询问也不一定询问的到啊QWQ,所以就当成几乎不会错啦。

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int N=100005; inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} int hd[N],to[N*10],ne[N*10],dc;
int num=1,n,m,Q,cnt,K,L,dfn[N];
ll val[N*10],a[66],Xor[N],c[66];
bool flag; inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;} inline ll getrand(){ return (ll)floor(rand()/(double)RAND_MAX*(double)1e19);} void dfs(int x,int fa){
dfn[x]=++dc;
for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa)
if(!dfn[to[i]]){
dfs(to[i],x),Xor[x]^=Xor[to[i]];
val[i]=val[i^1]=Xor[to[i]];
}
else if(dfn[to[i]]<dfn[x]){
val[i]=val[i^1]=getrand();
Xor[x]^=val[i],Xor[to[i]]^=val[i];
}
} inline bool ins(ll x){
for(int i=63;i>=0;i--) if(c[i]&x){
if(!a[i]){ a[i]=x; return 1;}
x^=a[i];
}
return 0;
} int main(){
srand(20010207);
c[0]=1; for(int i=1;i<64;i++) c[i]=c[i-1]+c[i-1]; n=read(),m=read();
for(int i=1,uu,vv;i<=m;i++){
uu=read(),vv=read();
add(uu,vv),add(vv,uu);
} dfs(1,0); for(Q=read();Q;memset(a,0,sizeof(a)),Q--){
K=read();
for(flag=1;K;K--){
L=read()^cnt;
if(!ins(val[L<<1])) flag=0;
}
cnt+=flag,puts(flag?"Connected":"Disconnected");
} return 0;
}

  

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int N=100005; inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} int hd[N],to[N*10],ne[N*10],dc;
int num=1,n,m,Q,cnt,K,L,dfn[N];
ll val[N*10],a[66],Xor[N],c[66];
bool flag; inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;} inline ll getrand(){ return (ll)floor(rand()/(double)RAND_MAX*(double)1e19);} void dfs(int x,int fa){
dfn[x]=++dc;
for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa)
if(!dfn[to[i]]){
dfs(to[i],x),Xor[x]^=Xor[to[i]];
val[i]=val[i^1]=Xor[to[i]];
}
else if(dfn[to[i]]<dfn[x]){
val[i]=val[i^1]=getrand();
Xor[x]^=val[i],Xor[to[i]]^=val[i];
}
} inline bool ins(ll x){
for(int i=63;i>=0;i--) if(c[i]&x){
if(!a[i]){ a[i]=x; return 1;}
x^=a[i];
}
return 0;
} int main(){
srand(20010207);
c[0]=1; for(int i=1;i<64;i++) c[i]=c[i-1]+c[i-1]; n=read(),m=read();
for(int i=1,uu,vv;i<=m;i++){
uu=read(),vv=read();
add(uu,vv),add(vv,uu);
} dfs(1,0); for(Q=read();Q;memset(a,0,sizeof(a)),Q--){
K=read()^cnt;
for(flag=1;K;K--){
L=read()^cnt;
if(!ins(val[L<<1])) flag=0;
}
cnt+=flag,puts(flag?"Connected":"Disconnected");
} return 0;
}

  

DZY Loves Chinese / DZY Loves Chinese II的更多相关文章

  1. tomcat chinese miscode and chinese input in IDEA

    JAVA_OPTS="$JAVA_OPTS -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF -8 -Duser.lang ...

  2. [CodeForces - 447C] C - DZY Loves Sequences

    C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...

  3. [CodeForces - 447B] B - DZY Loves Strings

    B - DZY Loves Strings DZY loves collecting special strings which only contain lowercase letters. For ...

  4. [CodeForces - 447A] A - DZY Loves Hash

    A - DZY Loves Hash DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert ...

  5. Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力

    D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...

  6. CodeForces 444C. DZY Loves Physics(枚举+水题)

    转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...

  7. 【BZOJ3563/BZOJ3569】DZY Loves Chinese I/II(随机化,线性基)

    [BZOJ3563/BZOJ3569]DZY Loves Chinese I/II(随机化,线性基) 题面 搞笑版本 正经版本 题面请自行观赏 注意细节. 题解 搞笑版本真的是用来搞笑的 所以我们来讲 ...

  8. [BZOJ3569]DZY Loves Chinese II(随机化+线性基)

    3569: DZY Loves Chinese II Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1515  Solved: 569[Submit][S ...

  9. 【BZOJ3563/3569】DZY Loves Chinese II 线性基神题

    [BZOJ3563/3569]DZY Loves Chinese II Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以 ...

随机推荐

  1. 【洛谷 P2042】 [NOI2005]维护数列(自闭记第一期)

    题目链接 首先,这题我是没A的..太毒瘤了 题目本身不难,都是\(Splay\)的基操,但是细节真的容易挂. 调了好久自闭了,果断放弃.. 希望本节目停更. 放上最终版本 #include <c ...

  2. java 错误: 找不到或无法加载主类解决方法

    1.配置好jdk与jre环境变量路径 https://www.cnblogs.com/xch-yang/p/7629351.html 2.在编译和运行的时候需要注意如下格式.

  3. Warning: File upload error - unable to create a temporary file in Unknown on line 0

    upload_tmp_dir 临时文件夹问题 上传文件提示 Warning: File upload error - unable to create a temporary file in Unkn ...

  4. upupw注入by pass

    http:' and updatexml(null,concat(0x5c,(/*!00000select SCHEMA_name*/from/*!information_schema*/.schem ...

  5. [Leetcode Week17]Copy List with Random Pointer

    Copy List with Random Pointer 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/copy-list-with-random- ...

  6. linux编程之文件操作

    在linux下用文件描述符来表示设备文件盒普通文件,文件描述符是一个整型的数据,所有对文件的操作都是通过文件描述符来实现的. 文件描述符是文件系统中连接用户空间和内核空间的枢纽,当我们打开一个或者创建 ...

  7. python 学记笔记 SQLalchemy

    数据库表是一个二维表,包含多行多列.把一个表的内容用Python的数据结构表示出来的话,可以用一个list表示多行,list的每一个元素是tuple,表示一行记录,比如,包含id和name的user表 ...

  8. linux===Ubuntu 上安装 Node.js

    https://www.cnblogs.com/andfly/p/6681487.html

  9. linux内核网络接收数据流程图【转】

    转自:http://blog.chinaunix.net/uid-23069658-id-3141409.html 4.3 数据接收流程图   各层主要函数以及位置功能说明:          1)s ...

  10. django wsgi nginx 配置

    """ WSGI config for HelloWorld project. It exposes the WSGI callable as a module-leve ...