这题一眼lct,然而

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
int n,m,k,fa[maxn],sta1[maxn*],sta2[maxn*],top,tt,ans[maxn];
int getfa(int x){
if(x!=fa[x]){
sta1[++top]=x;sta2[top]=fa[x];
fa[x]=getfa(fa[x]);
}
return fa[x];
}
struct edg{
int x,y,tim;
}e[maxn*];
struct que{
int num,c[];
}q[maxn];
void cdq(int l,int r){
int now=top;
if(l==r){
ans[l]=;
for(int i=;i<=q[l].num;++i){
int fx=getfa(e[q[l].c[i]].x);
int fy=getfa(e[q[l].c[i]].y);
if(fx!=fy){
ans[l]=;break;
}
}
while(top!=now)fa[sta1[top]]=sta2[top],top--;
return;
}
++tt;
int mid=l+r>>;
for(int i=l;i<=mid;++i)
for(int j=;j<=q[i].num;++j){
e[q[i].c[j]].tim=tt;
}
for(int i=mid+;i<=r;++i)
for(int j=;j<=q[i].num;++j)
if(e[q[i].c[j]].tim!=tt){
int fx=getfa(e[q[i].c[j]].x);
int fy=getfa(e[q[i].c[j]].y);
if(fx!=fy){
sta1[++top]=fx;sta2[top]=fa[fx];
fa[fx]=fy;
}
}
cdq(l,mid);
while(top!=now){fa[sta1[top]]=sta2[top];top--;}
++tt;
for(int i=mid+;i<=r;++i)
for(int j=;j<=q[i].num;++j){
e[q[i].c[j]].tim=tt;
}
for(int i=l;i<=mid;++i)
for(int j=;j<=q[i].num;++j)
if(e[q[i].c[j]].tim!=tt){//把后面的所有边中前面没删的加上;
int fx=getfa(e[q[i].c[j]].x);
int fy=getfa(e[q[i].c[j]].y);
if(fx!=fy){
sta1[++top]=fx;sta2[top]=fa[fx];
fa[fx]=fy;
}
}
cdq(mid+,r);
}
int main(){
cin>>n>>m;
for(int i=;i<=n;++i)fa[i]=i;
for(int i=;i<=m;++i){
scanf("%d%d",&e[i].x,&e[i].y);
e[i].tim=;
}
cin>>k;tt=;
for(int i=;i<=k;++i){
scanf("%d",&q[i].num);
for(int j=;j<=q[i].num;++j){
scanf("%d",&q[i].c[j]);
e[q[i].c[j]].tim=tt;
}
}
for(int i=;i<=m;++i)
if(e[i].tim!=tt){
int fx=getfa(e[i].x);
int fy=getfa(e[i].y);
if(fx!=fy)fa[fx]=fy;
}
cdq(,k);
for(int i=;i<=k;++i){
if(ans[i])puts("Connected");
else puts("Disconnected");
}
return ;
}

题解说可以cdq+并查集,于是复习了一下cdq;

bzoj3237(cdq+并查集)的更多相关文章

  1. bzoj3237 cdq分治+可撤销并查集

    https://www.lydsy.com/JudgeOnline/problem.php?id=3237 年轻的花花一直觉得cdq分治只能用来降维,不料竟然可以用来分治询问 N<=100000 ...

  2. 2018.10.01 bzoj3237: [Ahoi2013]连通图(cdq分治+并查集)

    传送门 cdq分治好题. 对于一条边,如果加上它刚好连通的话,那么删掉它会有两个大集合A,B.于是我们先将B中禁用的边连上,把A中禁用的边禁用,再递归处理A:然后把A中禁用的边连上,把B中禁用的边禁用 ...

  3. [BZOJ3237][AHOI2013]连通图(分治并查集)

    3237: [Ahoi2013]连通图 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1736  Solved: 655[Submit][Status ...

  4. hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)

    题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...

  5. BZOJ 4025: 二分图 [线段树CDQ分治 并查集]

    4025: 二分图 题意:加入边,删除边,查询当前图是否为二分图 本来想练lct,然后发现了线段树分治的做法,感觉好厉害. lct做法的核心就是维护删除时间的最大生成树 首先口胡一个分块做法,和hno ...

  6. 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5354 题意:求删去每个点后图是否存在奇环(n,m<=1e5) 解法:很经典的套路,和这题一样:h ...

  7. 【openjudge】C15C Rabbit's Festival CDQ分治+并查集

    题目链接:http://poj.openjudge.cn/practice/C15C/ 题意:n 点 m 边 k 天.每条边在某一天会消失(仅仅那一天消失).问每一天有多少对点可以相互到达. 解法:开 ...

  8. Codeforces 938G(cdq分治+可撤销并查集+线性基)

    题意: 有一个无向连通图,支持三个操作: 1 x y d : 新建一条x和y的无向边,长度为d 2 x y    :删除x和y之间的无向边 3 x y    :询问x到y的所有路径中(可以绕环)最短的 ...

  9. BZOJ3237:[AHOI2013]连通图(线段树分治,并查集)

    Description Input Output Sample Input 4 5 1 2 2 3 3 4 4 1 2 4 3 1 5 2 2 3 2 1 2 Sample Output Connec ...

随机推荐

  1. python经典案例

    前言:初学者对python的流程语句有一定的了解,但是运用起来总会磕磕碰碰.本文总结了一些初学者在学习python时做的经典案例 一.名片管理系统(限单个名片) info = {'name':'jam ...

  2. python基础与docker

    创建虚拟环境python3 -m venv venv (说明:python 2.X 并不支持) 激活虚拟环境macOS/Linux: source venv/bin/activateWindows: ...

  3. java itext替换PDF中的文本

    itext没有提供直接替换PDF文本的接口,我们可以通过在原有的文本区域覆盖一个遮挡层,再在上面加上文本来实现. 所需jar包: 1.先在PDF需要替换的位置覆盖一个白色遮挡层(颜色可根据PDF文字背 ...

  4. PhoenixFD插件流体模拟——UI布局【Gird】详解

    流体网格 本文主要讲解Grid折叠栏中的内容 主要内容 Overview 综述 Parameters 参数 General 普通参数 Example: Scene Scale Example: Gri ...

  5. MyCP -tx -xt 功能的Java实现

    MyCP -tx -xt 功能的Java实现 功能简介 java MyCP -tx XXX1.txt XXX2.bin 用来把文本文件(内容为十进制数字)转化为二进制文件 java MyCP -xt ...

  6. zigbee_蓝牙_wifi的比较与区别分析

    现在无线通读热了起来.三个最大的Wifi.ZigBee.蓝牙它们三个始终困惑着我.那么它们三个有什么区别呢? Zigbee 和蓝牙都是一项无线通信技术.ZigBee的传输距离视发射功率而定,有几百到几 ...

  7. jqgrid点击搜索无法重置参数问题

    var searchClick=false;//判断是否是第一次点击搜索 //当搜索按钮被单击时触发 function searchData(){ //创建jqGrid组件 console.log(' ...

  8. tmux复制模式

    复制模式支持滚屏等操作,进入方法为Ctrl + b再按"[",此时进入所谓的copy-mode 然后就可以用上下键或PageDn/PageUp浏览屏幕了. 想退出copy-mode ...

  9. 在Linux 安装Python3.5.6详细文档!!!!

    在Linux 安装Python3.5.6详细文档!!!! 1.安装相关依赖库(工具包) yum install gcc patch libffi-devel python-devel  zlib-de ...

  10. 安装CentOS 7 的yum 到 Radhat 7上,使其可以获取资源

    镜像资源: 1. http://mirrors.163.com/ 2. https://opsx.alibaba.com/mirror 从上列镜像资源下载如下rpm软件包 -rw-r--r--. 1 ...