第一次写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. mac 非安全模式 开启

    https://github.com/callmelaoda/communicate/issues/8 open -a Google\ Chrome --args --disable-web-secu ...

  2. Disharmony Trees HDU - 3015 树状数组+离散化

    #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using ...

  3. Hdu1042 N! (阶乘高精度模板)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  4. java语言额堂测试

    package java88; public class ScoreInformation { public ScoreInformation() {}; private String stunumb ...

  5. 03-SV过程语句和子程序

    1.过程语句 for语句.do-while语句.while语句 initial begin string cmd; int file,c; $display("=========== con ...

  6. 在 myeclipse 引入项目

    1.进入 myeclipse 在界面空白处,右键,出现如下图所示 2.选择 Import...,弹出如下图所示界面 3.双击上图红框内的内容,弹出如下图所示界面,然后点击按钮“Browse...”,选 ...

  7. Docker最全教程——从理论到实战(十六)

    前言 与其他语言相比,Go非常值得推荐和学习,真香!为什么?主要是可以直接编译成机器代码(性能优越,体积非常小,可达10来M,见实践教程图片)而且设计良好,上手门槛低.本篇主要侧重于讲解了Go语言的优 ...

  8. 修改url中参数值

    1.一种方法function changeUrlArg(url, arg, val){ var pattern = arg+'=([^&]*)'; var replaceText = arg+ ...

  9. CodeForces - 651C Watchmen (去重)

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  10. Windows下MongoDB的配置及其远程连接

    基本操作MongoDB的基本安装https://blog.csdn.net/heshushun/article/details/77776706启动和配置MongoDB服务参考博客https://bl ...