BZOJ 3563 DZY Loves Chinese
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的更多相关文章
- 3563: DZY Loves Chinese - BZOJ
Description神校XJ之学霸兮,Dzy皇考曰JC.摄提贞于孟陬兮,惟庚寅Dzy以降.纷Dzy既有此内美兮,又重之以修能.遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上有N座祭 ...
- BZOJ 3569 DZY Loves Chinese II
Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...
- BZOJ 3569 DZY Loves Chinese II 树上差分+线性基
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3569 Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅 ...
- BZOJ 3569: DZY Loves Chinese II [高斯消元XOR 神题]
http://www.lydsy.com/JudgeOnline/problem.php?id=3569 题意:多次询问一个无向连通图当图中某k条边消失时这个图是否联通 强制在线 太神啦啦啦啦啦啦啦啦 ...
- BZOJ 3569 DZY Loves Chinese II ——线性基
[题目分析] 腊鸡题目卡题面. 大概的意思就是给一张无向图,每次删掉其中一些边,问是否联通. 首先想到的是Bitset,可以做到n^2/64.显然过不了. 然而这是lyd在给我们讲线性基的时候的一道题 ...
- bzoj 3569 DZY Loves Chinese II 随机算法 树上倍增
题意:给你一个n个点m条边的图,有若干组询问,每次询问会选择图中的一些边删除,删除之后问此图是否联通?询问之间相互独立.此题强制在线. 思路:首先对于这张图随便求一颗生成树,对于每一条非树边,随机一个 ...
- BZOJ 3569: DZY Loves Chinese II(线性基)
传送门 解题思路 首先构造出一个生成树,考虑不连接的情况.假设连通两点的非树边和树边都断掉后不连通,那么可以给所有的非树边随机一个互不相同的值,然后树边的权值为过他两端点的非树边权值的异或和,这个可以 ...
- 【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 ...
- ●BZOJ 3309 DZY Loves Math
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...
随机推荐
- CSS 边框 阴影 效果
CSS 边框 阴影 效果 以下将css实现阴影效果,以便须要朋友们,直接上代码 #shadow1{ width: 200px; height: 100px; color: white; backgro ...
- allocator例子
13.39 编写自己的StrVec,包括自己版本的reserve.capacity和resize. 13.40 为StrVec添加一个构造函数,它接受一个initializer_list<str ...
- plupload使用指南(转)
转自http://www.cnblogs.com/2050/p/3913184.html 现在随着html5技术的逐渐推广和普及,再去使用以flash为上传手段的SWFUpload显然就有点过时了,毕 ...
- 文件权限和目录权限详解(rwx)
[文件] r:可读,可以使用cat命令查看文件内容: w:可写,可以编辑或删除文件: x:可执行,可以当作命令提交给内核 [目录] r:可以对此目录执行ls,列出内部所有文件 w:可以在此目录创建文件 ...
- Eureka Web UI URL(eureka显示主界面路径设定)
http://stackoverflow.com/questions/30200988/spring-cloud-with-eureka-eureka-web-ui-url ************* ...
- datebox清除按钮,datebox加上清除按钮,easyui datebox加上清除按钮
datebox加上清除按钮,easyui datebox加上清除按钮 >>>>>>>>>>>>>>>>& ...
- (转)ie浏览器判断
常用的 JavaScript 检测浏览器为 IE 是哪个版本的代码,包括是否是最人极端厌恶的 ie6 识别与检测. var isIE=!!window.ActiveXObject; var isIE6 ...
- jQuery Ajax 实例 全解析
jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯. 废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是 ...
- # Day04-Android
Day04-Android 标签(空格分隔): andrroid 1.制作界面 2.在写Activity. Logcat LayoutInflate把Xml转换纯成View的工具. 自定义吐司 Lay ...
- sql Server 触发器 调用java.
在这里,通过 xp_cmdshell 调用java程序. 步骤: 1)开启 xp_cmdshell(sql Server 2008): 通过如下命令开启: -- To allow advanced o ...