BZOJ 3569 DZY Loves Chinese II
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}\)。
为了体现在线,\(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
3 7 0 3
4 0 7 4 6
2 2 7
4 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\)
数据保证没有重边与自环
这题有个很屌的做法。对于此图,我们给抽出一颗生成树,给每条非树边都rand一个权值,每条树边的权值为所有覆盖它的权值的异或值。对于删掉的边,我们只要寻找删掉的边中权值是否能异或出\(0\)来,高斯消元即可。
#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("3569.in","r",stdin);
freopen("3569.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();
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 3569 DZY Loves Chinese II的更多相关文章
- 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(线性基)
传送门 解题思路 首先构造出一个生成树,考虑不连接的情况.假设连通两点的非树边和树边都断掉后不连通,那么可以给所有的非树边随机一个互不相同的值,然后树边的权值为过他两端点的非树边权值的异或和,这个可以 ...
- BZOJ 3563 DZY Loves Chinese
Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...
- [BZOJ3569]DZY Loves Chinese II(随机化+线性基)
3569: DZY Loves Chinese II Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1515 Solved: 569[Submit][S ...
- 【BZOJ3563/3569】DZY Loves Chinese II 线性基神题
[BZOJ3563/3569]DZY Loves Chinese II Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以 ...
- 【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 ...
随机推荐
- [PHP] find ascii code in string
if (strpos($data ,chr(0x95)) !== false) { echo 'true'; }else{ echo "false"; }
- cocos2d-x plist+wen使用
http://zhan.renren.com/tag?value=cocos2dx&from=template http://blog.csdn.net/zhanglongit/article ...
- 调试php的soapServer
用.NET的webservice做调试很轻松. 用soapserver的try和cacth获取不了多少信息
- Bootstrap--全局CSS样式之概览
(1)HTML5文档类型 Bootstrap 使用到的某些 HTML 元素和 CSS 属性需要将页面设置为 HTML5 文档类型.在项目中的每个页面都要参照下面的格式进行设置. Code<!DO ...
- 自动显示git分支--安装oh-my-zsh(Ubuntu环境)
1,安装zsh sudo apt-get install zsh 2,克隆项目 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...
- [字符串] AppMessage--字符串返回帮助类 (转载)
点击下载 AppMessage.rar 这个类是关于AppMessage的帮助类,主要是格式化返回字符串的里面会有很多的提供字符的格式以及预设置内容,大家可以直接使用的看下面代码吧 /// <s ...
- SQL Server 中WITH (NOLOCK)
with(nolock)的功能: 1: 指定允许脏读.不发布共享锁来阻止其他事务修改当前事务读取的数据,其他事务设置的排他锁不会阻碍当前事务读取锁定数据.允许脏读可能产生较多的并发操作,但其代价是读取 ...
- T-SQL切割字符串方法小结 2
有表tb, 如下: id value ----------- ----------- 1 aa,bb 2 aaa,bbb,ccc 欲按id,分拆value列, 分拆后结果如下: id value -- ...
- linux启动黑屏或无法进入会话管理器
原因是因为更新软件时删除了/etc中的xserver配置文件,进入livecd将相关文件拷贝即可
- WCF大文件传输服务
由于项目需要,自己写一个基于WCF的大文件传输服务雏形.觉得有一定的参考价值,因此放在网上分享. 目前版本为v1.1特点如下: 1.文件传输端口为18650 2.上传和下载文件 3.支持获取文件传输状 ...