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\)个编号\(c_{1} \sim c_{K}\):表示\(K\)条边,编号为\(c_{1} \sim c_{K}\)。

为了体现在线,K以及\(c_{1} \sim c_{K}\)均需异或之前回答为连通的个数。

Output

对于每个询问输出:连通则为‘Connected’,不连通则为‘Disconnected’(不加引号)

Sample Input

5 10

2 1

3 2

4 2

5 1

5 3

4 1

4 3

5 2

3 1

5 4

5

1 1

2 7 0 3

6 0 7 4 6

1 2 7

0 5 0 2 13

Sample Output

Connected

Connected

Connected

Connected

Disconnected

HINT

\(N \le 100000,M \le 500000,Q \le 50000,1 \le K \le 15\)

数据保证没有重边与自环

逗比题,考验语文能力。由于\(K\)也异或了答案,我们只要看读了几条边就可知道答案了。 呵呵,我还写的正解(见BZOJ 3569 DZY Loves Chinese II)。。。

#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std; #define maxn (100010)
#define maxm (1000010)
int K,n,m,father[maxn],bit[maxn],dep[maxn],ans;
int side[maxn],next[maxm*2],toit[maxm*2],num = 1,up[maxn];
bool exist[maxm],sign; vector <int> ch[maxn]; inline int getint()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} inline void add(int a,int b) { next[++num] = side[a]; side[a] = num; toit[num] = b; } inline void ins(int a,int b) { add(a,b); add(b,a); } struct node
{
int u,v,w;
inline void read() { u = getint(),v = getint(); ins(u,v); }
}edge[maxm]; inline int find(int a) { if (father[a] != a) father[a] = find(father[a]); return father[a]; } inline void dfs(int now,int fa)
{
for (int i = side[now];i;i = next[i])
{
if (toit[i] == fa||!exist[i>>1]) continue;
up[toit[i]] = i,ch[now].push_back(toit[i]),dep[toit[i]] = dep[now]+1,dfs(toit[i],now);
}
} inline void deal(int a,int b,int w)
{
if (dep[a] < dep[b]) swap(a,b);
while (dep[a] != dep[b])
{
edge[up[a]>>1].w ^= w;
a = toit[up[a]^1];
}
if (a == b) return;
while (a != b)
{
edge[up[a]>>1].w ^= w;
a = toit[up[a]^1];
edge[up[b]>>1].w ^= w;
b = toit[up[b]^1];
}
} inline void ready()
{
for (int i = 1;i <= n;++i) father[i] = i;
int cnt = 0;
for (int i = 1;i <= m;++i)
{
int r1 = find(edge[i].u),r2 = find(edge[i].v);
if (r1 != r2) ++cnt,father[r1] = r2,exist[i] = true;
if (cnt == n-1) break;
}
dfs(1,0);
for (int i = 1;i <= m;++i) if (!exist[i]) edge[i].w = rand()%(1<<30),deal(edge[i].u,edge[i].v,edge[i].w);
} inline bool connect()
{
int now = 1;
for (int i = 29;i >= 0&&now <= K;--i)
{
for (int j = now;j <= K;++j)
if (bit[j] & (1<<i))
{
swap(bit[now],bit[j]);
break;
}
if (bit[now]&(1<<i))
{
for (int j = 1;j <= K;++j)
if (j != now&&(bit[j]&(1<<i))) bit[j] ^= bit[now];
++now;
}
}
for (int i = 1;i <= K;++i) if (!bit[i]) return false;
return true;
} int main()
{
freopen("3563.in","r",stdin);
freopen("3563.out","w",stdout);
srand(19980402);
n = getint(),m = getint();
for (int i = 1;i <= m;++i) edge[i].read();
ready();
int Q = getint();
while (Q--)
{
K = getint(); K ^= ans;
for (int i = 1;i <= K;++i)
{
int a = getint(); a ^= ans;
bit[i] = edge[a].w;
}
sign = connect();
if (sign) puts("Connected");
else puts("Disconnected");
ans += sign;
}
return 0;
}

BZOJ 3563 DZY Loves Chinese的更多相关文章

  1. 3563: DZY Loves Chinese - BZOJ

    Description神校XJ之学霸兮,Dzy皇考曰JC.摄提贞于孟陬兮,惟庚寅Dzy以降.纷Dzy既有此内美兮,又重之以修能.遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上有N座祭 ...

  2. BZOJ 3569 DZY Loves Chinese II

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  3. BZOJ 3569 DZY Loves Chinese II 树上差分+线性基

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3569 Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅 ...

  4. BZOJ 3569: DZY Loves Chinese II [高斯消元XOR 神题]

    http://www.lydsy.com/JudgeOnline/problem.php?id=3569 题意:多次询问一个无向连通图当图中某k条边消失时这个图是否联通 强制在线 太神啦啦啦啦啦啦啦啦 ...

  5. BZOJ 3569 DZY Loves Chinese II ——线性基

    [题目分析] 腊鸡题目卡题面. 大概的意思就是给一张无向图,每次删掉其中一些边,问是否联通. 首先想到的是Bitset,可以做到n^2/64.显然过不了. 然而这是lyd在给我们讲线性基的时候的一道题 ...

  6. bzoj 3569 DZY Loves Chinese II 随机算法 树上倍增

    题意:给你一个n个点m条边的图,有若干组询问,每次询问会选择图中的一些边删除,删除之后问此图是否联通?询问之间相互独立.此题强制在线. 思路:首先对于这张图随便求一颗生成树,对于每一条非树边,随机一个 ...

  7. BZOJ 3569: DZY Loves Chinese II(线性基)

    传送门 解题思路 首先构造出一个生成树,考虑不连接的情况.假设连通两点的非树边和树边都断掉后不连通,那么可以给所有的非树边随机一个互不相同的值,然后树边的权值为过他两端点的非树边权值的异或和,这个可以 ...

  8. 【BZOJ3569】DZY Loves Chinese II

    [BZOJ3569]DZY Loves Chinese II 题面 bzoj 题目大意: 给你一张\(N(1\leq N\leq 10^5)\)个点\(M(1\leq M\leq 5\times 10 ...

  9. ●BZOJ 3309 DZY Loves Math

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...

随机推荐

  1. 聊一聊 Android 6.0 的运行时权限

    权限一刀切 棉花糖运行时权限 权限的分组 正常权限 正常权限列表 特殊权限危险权限 请求SYSTEM_ALERT_WINDOW 请求WRITE_SETTINGS 必须要支持运行时权限么 不支持运行时权 ...

  2. POSIX字符类型

    [:alnum:] 字母与数字 [:alpha:] 字母 [:blank:] 空格与制表符 [:cntrl:] 控制字符 [:digit:] 数字 [:graph:] 可打印的与可见的(不包括空格)字 ...

  3. Linux Bash算数运算方法小结

    A= B= 方法1:let(中间无空格) let C=$A+$B 方法2:$[  ] C=$[$A+$B] 方法3:$(()) C=$(($A+$B)) 方法4:expr(中间有空格) C=`expr ...

  4. spring+hibernate+jpa+Druid的配置文件,spring整合Druid

    spring+hibernate+jpa+Druid的配置文件 spring+hibernate+jpa+Druid的完整配置 spring+hibernate+jpa+Druid的数据源配置 spr ...

  5. SQL语句对应的LINQ和Lambda语句

    1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname,ssex,class from studentLinq:    from s in Student ...

  6. HDU-1015(暴力)

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is loc ...

  7. HTML+CSS基础学习笔记(8)

    一.水平居中设置--行内元素 如果设置元素为文本.图片等行内元素时,水平居中是通过给父元素设置text-align:center来实现的 二.水平居中设置 --定宽块状元素 #当被设置元素为块状元素时 ...

  8. html不同文档类型支持的元素标签

  9. (转)Spring MVC

    资源下载: Spring_MVC_教程_快速入门_深入分析V1.1.pdf SpringMVC核心配置文件示例.rar 作者:赵磊 博客:http://elf8848.iteye.com 目录 一.前 ...

  10. javascript类继承系列五(其他方式继承)

    除了前面学习的三种继承外,还有另外三种:原型继承寄生继承,寄生组合继承都是以: function object(o) { function F() { } F.prototype = o; retur ...