LCT模版题。。。。

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <cmath>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define l(x) c[x][0]
#define r(x) c[x][1]
#define f(x) Father[x]
#define h(x) Head[x]
#define maxn 10009
#define inf 0x7fffffff
using namespace std;
inline int read()
{
int x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
int n, c[maxn][2], Head[maxn], Father[maxn];
bool rev[maxn]; inline void pushdown(int x)
{
rev[x]^=1, rev[l(x)]^=1, rev[r(x)]^=1;
swap(l(l(x)), r(l(x))), swap(l(r(x)), r(r(x)));
}
inline void rotate(int x)
{
int y=f(x), z=f(y), l=(c[y][1]==x), r=l^1;
if (z) c[z][c[z][1]==y]=x;
f(c[x][r])=y, f(y)=x, f(x)=z;
c[y][l]=c[x][r]; c[x][r]=y;
}
inline void Splay(int x)
{
if (!x) return; if (rev[x]) pushdown(x); int y;
while (f(x))
{
if (rev[y=f(x)]) pushdown(y), pushdown(x);
if (!f(y)) h(x)=h(y), h(y)=0;
rotate(x);
}
}
inline void Acc(int x)
{
int cmp=x, y; Splay(x);
f(r(x))=0, h(r(x))=x, r(x)=0;
while (h(x))
Splay(y=h(x)), f(r(y))=0, h(r(y))=y, r(y)=x, f(x)=y, h(x)=0, x=y;
Splay(cmp);
}
inline void Eve(int x){Acc(x); rev[x]^=1; swap(l(x), r(x));}
inline int Top(int x){Acc(x); int now=x; while (l(now)) now=l(now); return now;}
inline void Build(){rep(i, 1, n) l(i)=r(i)=h(i)=f(i)=0;}
inline void Connect(int x, int y){Eve(x); Eve(y); Splay(y); h(x)=y;}
inline void Destroy(int x, int y){Eve(x); Acc(y); f(x)=l(y)=0;}
inline void Query(int x, int y){if (Top(x)==Top(y)) puts("Yes"); else puts("No");}
int main()
{
n=read(); int m=read(); Build();
rep(i, 1, m)
{
char ch[5]; scanf("%s", ch); int x=read(), y=read();
if (ch[0]=='C') Connect(x, y); else if (ch[0]=='D') Destroy(x, y); else Query(x, y);
}
return 0;
}

BZOJ-2049 [SDOI2008]洞穴勘测的更多相关文章

  1. BZOJ 2049 SDOI2008 洞穴勘测 LCT板子

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 题意概述:给出N个点,一开始不连通,M次操作,删边加边,保证图是一个森林,询问两点连 ...

  2. BZOJ 2049 [SDOI2008]洞穴勘测 (LCT)

    题目大意:维护一个森林,支持边的断,连,以及查询连通性 LCT裸题 洛谷P2147传送门 1A了,给自己鼓鼓掌 #include <cstdio> #include <algorit ...

  3. bzoj 2049 Cave 洞穴勘测(LCT)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 动态树入门题,不需要维护任何信息. 我用的是splay,下标实现的lct. #in ...

  4. P2147 [SDOI2008]洞穴勘测(LCT)

    P2147 [SDOI2008]洞穴勘测 裸的LCT. #include<iostream> #include<cstdio> #include<cstring> ...

  5. P2147 [SDOI2008]洞穴勘测

    P2147 [SDOI2008]洞穴勘测 思路 没办法,我就是喜欢板子都想发的人 都是基础操作,不多说了 代码 #include <bits/stdc++.h> #define ls ch ...

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

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

  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)

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

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

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

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

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

随机推荐

  1. SC || Chapter 5 复习向

    可复用性 ┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉ 行为子结构 对于父子的继承关系的要求: ·子类可以增加方法,但不可以删 ·子类需实现抽象类型中未实现的方法 ·子类重写(override)的方法必须 ...

  2. 如何远程连接Windows server上的MySQL服务

    废话不多说,直接开干 首先要打开服务器的MySQL端口号:3306(当然,也可以把服务器的防火墙直接关闭,不过不安全) 1.打开服务器管理器,有个高级安全Windows防火墙,下面有一个入站规则, 右 ...

  3. IEDA的安装与破解

    百度搜索IDEA 进入官网下载 https://www.jetbrains.com/idea/download/#section=windows 2.下载好双击即可 3. 完成破解

  4. JavaScript——图片懒加载

    前言 有一个朋友问我这个问题,刚好有时间,现在就简单的写个Demo~ github | https://github.com/wangyang0210/bky/tree/picLoadLazy 内容 ...

  5. HTML5<nav>元素

    HTML5中<nav>元素定义页面导航链接的部分区域,但并不是所有的链接都放到nav元素里面. 实例: <header id="pageHeader"> & ...

  6. OI算法复习

    搜集一些算法,赛前背一背有好处的 转自各大网站 前排感谢:hzwer.风了咕凉 前辈...Orz 快速读入: int read() { ,f=;char ch=getchar(); ;ch=getch ...

  7. Codeforces Round #513 (rated, Div. 1 + Div. 2)

    前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...

  8. [CF] 180 E. Cubes

    对同类元素双指针扫描 #include<iostream> #include<cstring> #include<cstdio> #include<vecto ...

  9. List<Object>删除某一个Object

    1.直接删除: List<LineShop> tlineprices  = new ArrayList<>(); tlineprices.remove(0); 2.使用遍历删除 ...

  10. light oj 1104 Birthday Paradox (概率题)

    Sometimes some mathematical results are hard to believe. One of the common problems is the birthday ...