第一次写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. codeforceCodeForces - 1107G

    单调栈 RMQ #include<iostream> #include<cstdio> #include<cmath> #include<cstring> ...

  2. Constructing Roads POJ - 2421 最小生成树板子题

    #include<iostream> #include<cstring> #include<algorithm> using namespace std; ; in ...

  3. The Way to Home CodeForces - 910A

    4个月前做的一道题,当时不知道为什么,写了一个bfs,直接就超时了. 现在再看这个题目,发现就是一个简单的贪心,每次走最远即可. #include <bits/stdc++.h> usin ...

  4. springBoot代码和依赖分开打包

    目的: 1.分离代码和依赖(包括第三方的引入包) 2.分离配置文件到外部 3.修改/META-INF/MANIFEST.MF中加载依赖包的位置和启动类,包含第三方依赖jar包 先查看项目的结构 由于我 ...

  5. 1级搭建类108-Oracle 11gR2 SI FS(Windows Server 2019)公开

    Oracle 11gR2 单实例文件系统在Windows Server 2019上的安装 在线查看

  6. 关于Javascript闭包的理解

    以下内容属个人理解,如有看不明白或漏洞之处,纯属水平不佳,还望见谅. 关于闭包,高程里的定义是:指有权访问另一个函数作用域中的变量的函数.创建闭包最常见的方法就是在一个函数的内部再创建一个函数. 这里 ...

  7. Turtle模块基本方法和使用(画布)

      方法 简写 描述 例子 移动和绘制 forward() fd() 前进 turtle.forward(10):前进10个单位 backward() bk().back() 后退 turtle.ba ...

  8. jQuery---自定义动画 animate();

    自定义动画 animate(); 第一个参数:{对象},里面可以传需要动画的样式 第二个参数:speed 动画的执行时间 第三个参数:easing 动画的执行效果 第四个参数:callback 回调函 ...

  9. jQuery---基本的选择器

    基本选择器 名称 用法 描述 ID选择器 $(“#id”); 获取指定ID的元素 类选择器 $(“.class”); 获取同一类class的元素 标签选择器 $(“div”); 获取同一类标签的所有元 ...

  10. 自动生成admin(后台)

    public --->>>>index.php 入口文件如下: // +---------------------------------------------------- ...