Solution

$LCT$ 打上 $cut$ , $link$ 和 $finroot$ 即可

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
using namespace std; const int N = 1e4 + ; int n, m; int read() {
int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar())
if (c == '-') p = -;
for (; c >= '' && c <= ''; c = getchar())
X = X * + c - '';
return X * p;
} namespace LCT {
int f[N], ch[N][], tun[N];
#define lc(x) ch[x][0]
#define rc(x) ch[x][1] int isroot(int x) {
return rc(f[x]) != x && lc(f[x]) != x;
} int get(int x) {
return rc(f[x]) == x;
} void rev(int x) {
swap(lc(x), rc(x));
tun[x] ^= ;
} void pushdown(int x) {
if (tun[x]) {
if (lc(x)) rev(lc(x));
if (rc(x)) rev(rc(x));
tun[x] = ;
}
} void pd(int x) {
if (!isroot(x))
pd(f[x]);
pushdown(x);
} void rotate(int x) {
int old = f[x], oldf = f[old], son = ch[x][get(x) ^ ];
if (!isroot(old)) ch[oldf][get(old)] = x;
ch[x][get(x) ^ ] = old;
ch[old][get(x)] = son;
f[old] = x; f[x] = oldf; f[son] = old;
} void splay(int x) {
pd(x);
for (; !isroot(x); rotate(x))
if (!isroot(f[x]))
rotate(get(f[x]) == get(x) ? f[x] : x);
} void access(int x) {
for (int y = ; x; y = x, x = f[x])
splay(x), ch[x][] = y;
} void mroot(int x) {
access(x); splay(x); rev(x);
} int findr(int x) {
access(x); splay(x);
while(lc(x)) pushdown(x), x = lc(x);
return x;
} void split(int x, int y) {
mroot(x); access(y); splay(y);
} void cut(int x, int y) {
split(x, y);
f[x] = ch[y][] = ;
} void link(int x, int y) {
mroot(x);
f[x] = y;
}
}using namespace LCT; int main()
{
n = rd; m = rd;
for (; m; m--) {
char op[];
scanf("%s", op);
if (op[] == 'Q') {
int u = rd, v = rd;
mroot(u);
if (findr(v) != u)
puts("No");
else puts("Yes");
}
if (op[] == 'C') {
int u = rd, v = rd;
link(u, v);
}
if (op[] == 'D') {
int u = rd, v = rd;
cut(u, v);
}
}
}

Luogu 2147 洞穴勘测 - LCT的更多相关文章

  1. 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测 LCT/并查集

    两种方法: 1.LCT 第一次LCT,只有link-cut和询问,无限T,到COGS上找了数据,发现splay里的父亲特判出错了(MD纸张),A了,好奇的删了反转T了.... #include < ...

  2. [BZOJ2049] [SDOI2008] Cave 洞穴勘测 (LCT)

    Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...

  3. bzoj 2049: [Sdoi2008]Cave 洞穴勘测 (LCT)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2049 题面: 2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 1 ...

  4. BZOJ2049[Sdoi2008]洞穴勘测——LCT

    题目描述 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好两个洞穴.假如 ...

  5. 洛谷P2147[SDOI2008]洞穴勘测(lct)

    题目描述 辉辉热衷于洞穴勘测. 某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好两个洞穴.假 ...

  6. 【bzoj2049】[Sdoi2008]Cave 洞穴勘测 LCT

    题目描述 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好两个洞穴.假如 ...

  7. 【BZOJ2049】【SDOI2008】洞穴勘测 [LCT]

    洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 辉辉热衷于洞穴勘测.某天,他按照地 ...

  8. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...

  9. [BZOJ2049][Sdoi2008]Cave 洞穴勘测 LCT模板

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 9705  Solved: 4674[Submit] ...

随机推荐

  1. led 的 platform驱动实现

    http://www.linuxidc.com/Linux/2014-03/97756.htm http://blog.sina.com.cn/s/blog_6b94d5680101cn0t.html ...

  2. SVM参数解析

    一.Opencv中的核函数定义(4种): 1.CvSVM::LINEAR : 线性内核,没有任何向映射至高维空间,线性区分(或回归)在原始特点空间中被完成,这是最快的选择. 2.CvSVM::POLY ...

  3. ubuntu18换国内源

    编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目(操作前请做好相应备份): ##中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ ...

  4. centos7 关闭 防火墙

    CentOS 7 默认使用的是firewall作为防火墙 关闭firewall: systemctl stop firewalld.service  #停止firewall systemctl dis ...

  5. VSC KeyNote

    [VSC KeyNote] 1.前后跳转. Alt + LeftArrow, Alt + RightArrow 2.缩进问题. vsc默认缩进为4,但js代码里缩进依旧是2. 因为vscode默认启用 ...

  6. linux下mysql升级

    最近漏洞扫描,扫描出了数据库存在中高危漏洞,于是迫切需要进行数据库升级.上网查了各种资料,说法很多,也到自己虚拟机上试了好多方法,终于倒腾出来,做下小总结记录一下. 升级操作: 1.到mysql官网h ...

  7. linux命令清除服务器缓存

    linux 服务器开了某项服务或程序后,内存占用的非常大,停止服务或关闭进程后,内存不会立即释放,需要手动释放,使用命令 echo 3 > /proc/sys/vm/drop_chaches 释 ...

  8. IDEA中配置JUnit单元测试

    参考安装教程:https://www.jianshu.com/p/c37753b6dbd6 如果想用junit4的话,需要在pom.xml中配置. 需要安装JUnitGenerator V2.0插件, ...

  9. BP神经网络学习

    人工神经元模型     S型函数(Sigmoid) 双极S型函数 神经网络可以分为哪些? 按照连接方式,可以分为:前向神经网络 vs. 反馈(递归)神经网络 按照学习方式,可以分为:有导师学习神经网络 ...

  10. Array 遍历数组

    public static void main(String args){ int a[][] = new int[3][4]; for(int i=0;i<a.length;i++){ for ...