第一次写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. gulp常用插件之gulp-filter使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-filter这是一款可以把stream里的文件根据一定的规则进行筛选过滤. 更多使用文档请点击访问gulp-filter工具官网. 安装 ...

  2. the simmon effect(in psychology) :build the function of subject_information(modify the experiment programme),before we begin the experiment

    #the real experiment for simon effect #load the library which is our need import pygame import sys i ...

  3. PAT (Basic Level) Practice (中文)1031 查验身份证 (15 分)

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  4. 1级搭建类111-Oracle 19c SI FS(Windows Server 2019)公开

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

  5. 解决shell 报错:syntax error: unexpected end of file

    debug  shell:执行 sh -x test.sh vi test.sh :set fileformat=unix :wq解决问题原因是我在windows pycharm 写的格式不符合uni ...

  6. 用友UAP NC 单据新增数据时抛出"流程平台缓存中不存在该单据或交易类型=HB06"

    正常单据新增时,抛出异常"流程平台缓存中不存在该单据或交易类型=HB06"

  7. python:利用smtplib发送邮件详解

    本文转自:https://www.cnblogs.com/insane-Mr-Li/p/9121619.html 自动化测试中,测试报告一般都需要发送给相关的人员,比较有效的一个方法是每次执行完测试用 ...

  8. JavaDay2(中)

    Java循环与分支练习 习题1: 输出1~100内前5个可以被3整除的数. public class Day2_Test1 { //输出1~100内前5个可以被3整除的数. public static ...

  9. sqlalchemy_mptt一次调优

    问题背景: 我用sqlalchemy_mptt构建了一个多级分类项目,数据库用了sqlite.随着数据条数越来越多,写入速度逐渐变慢,一棵树的插入甚至需要1分钟,远远不能满足需求 分析思路: 1. 批 ...

  10. JDBC——PreparedStatement执行SQL的对象

    Statement的子接口,预编译SQL,动态SQL 功能比爹强大 用来解决SQL注入的 预编译SQL:参数使用?作为占位符,执行SQL的时候给?赋上值就可以了 使用步骤: 1.导入驱动jar包 复制 ...