第一次写lct

(这是一道lct裸题

这次没有可爱(划掉)的同学教我,虽然有模板,但是配合网上的讲解还是看不懂QAQ

然后做了几道题之后总算有些感觉辣

于是决定给自己挖个坑,近期写一个lct详解(不过像我这么懒的人= =

下面是代码

 /**************************************************************
Problem: 2049
User: cminus
Language: C++
Result: Accepted
Time:1532 ms
Memory:984 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
#define kd(x) (ch[fa[x]][1] == x)
#define setc(f, c, k) (ch[fa[c] = f][k] = c)
#define isRoot(x) (ch[fa[x]][0] != x and ch[fa[x]][1] != x)
#define ls ch[x][0]
#define rs ch[x][1]
const int N = ; int fa[N], ch[N][], n, m;
bool mark[N]; inline void push(int x){
if (mark[x]){
mark[x] = false;
mark[ls] ^= ;
mark[rs] ^= ;
swap(ls, rs);
}
}
stack < int > S;
inline void pushDown(int x) {
S.push(x);
while (!isRoot(x))
S.push(x = fa[x]);
while (!S.empty())
push(S.top()), S.pop();
} inline void rotate (int x) {
int y = fa[x], k = kd(x);
setc(y, ch[x][k ^ ], k);
if (isRoot(y)) fa[x] = fa[y];
else setc(fa[y], x, kd(y));
setc(x, y, k ^ );
} inline void splay (int x) {
pushDown(x);
while (! isRoot(x)) {
if (! isRoot(fa[x]))
if (kd(x) == kd(fa[x])) rotate(fa[x]);
else rotate(x);rotate(x);
}
} inline void access(int x) {
int t = ;
while (x) {
splay(x);
rs = t; t = x; x = fa[x];
}
} inline void makeRoot(int u) {
access(u); splay(u);
mark[u] ^= ;
} inline void link(int u, int v){
makeRoot(u); fa[u] = v;
} inline void cut(int u, int v){
makeRoot(u);
access(v); splay(v);
fa[u] = ch[v][] = ;
} inline int findRoot(int x) {
while(fa[x]) x = fa[x];
return x;
}
int main(){
scanf("%d %d", &n, &m);
char str[];
while(m--){
int u, v;
scanf("%s %d %d", str, &u, &v);
if (*str == 'C') link(u, v);
else if (*str == 'D') cut(u, v);
else puts((findRoot(u) == findRoot(v)) ? "Yes" : "No");
}
return ;
}

bzoj 2049: [Sdoi]Cave 洞穴探测 (LCT)的更多相关文章

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

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

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

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

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

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 省选之前来切一道数据结构模板题. 题意 这是一道模板题. N个点,M次操作,每次加边/ ...

  4. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 (LCT维护连通性)

    直接把x设为根,然后查询y所在联通块的根是不是x就行了. CODE #include <cstdio> #include <cstring> #include <algo ...

  5. BZOJ 2049: [Sdoi2008]Cave 洞穴勘測 LCT

    入门级LCT: 仅仅有 Cut Link 2049: [Sdoi2008]Cave 洞穴勘測 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 3073 ...

  6. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 (动态树入门)

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

  7. bzoj 2049: [Sdoi2008]Cave 洞穴勘测 动态树

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

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

    题目链接:BZOJ - 2049 题目分析 LCT的基本模型,包括 Link ,Cut 操作和判断两个点是否在同一棵树内. Link(x, y) : Make_Root(x); Splay(x); F ...

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

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2049 [题意] 给定森林,可能有连边或断边的操作,回答若干个连通性的询问. [思路] ...

随机推荐

  1. LeetCode:27 移除元素

    给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成 ...

  2. js 数据类型的转换

    1. 字符串转化为数字 Number(1) parseInt(1) parseFloat(1) 区别: number 参数只要含有非数字,结果就是NaN,

  3. 内网hash传递

    前言: 我们在平常打点的时候,遇到有内网或者有域的环境的时候,我们只获得了内网中的一台机子的shell,由这台机子我们可以获得这台机子所在的网段的相关其他主机.比如说有域的时候的域控机,有多层内网的堡 ...

  4. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  5. python3练习100题——044

    41-43讲关于python的变量范围,没有什么别的内容,我删除了. 原题链接:http://www.runoob.com/python/python-exercise-example44.html ...

  6. 【Unity|C#】基础篇(17)——字符串处理(String/StringBuilder)

    [学习资料] <C#图解教程>(第25章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  7. HDU2612 Find a way (双广搜)

    Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year ...

  8. [Python]python对csv去除重复行 python 2020.2.11

    用pandas库的.drop_duplicates函数 代码如下: import shutil import pandas as pd frame=pd.read_csv('E:/bdbk.csv', ...

  9. linux命令解压压缩rar文件的详细步骤

    参考文件:https://www.cnblogs.com/qinglin/p/9007939.html

  10. C++——动态内存分配2-创建对象数组

    //创建对象数组 #include<iostream> using namespace std; class Point { public:        Point()       {  ...