BZOJ-2049 [SDOI2008]洞穴勘测
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]洞穴勘测的更多相关文章
- BZOJ 2049 SDOI2008 洞穴勘测 LCT板子
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 题意概述:给出N个点,一开始不连通,M次操作,删边加边,保证图是一个森林,询问两点连 ...
- BZOJ 2049 [SDOI2008]洞穴勘测 (LCT)
题目大意:维护一个森林,支持边的断,连,以及查询连通性 LCT裸题 洛谷P2147传送门 1A了,给自己鼓鼓掌 #include <cstdio> #include <algorit ...
- bzoj 2049 Cave 洞穴勘测(LCT)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 动态树入门题,不需要维护任何信息. 我用的是splay,下标实现的lct. #in ...
- P2147 [SDOI2008]洞穴勘测(LCT)
P2147 [SDOI2008]洞穴勘测 裸的LCT. #include<iostream> #include<cstdio> #include<cstring> ...
- P2147 [SDOI2008]洞穴勘测
P2147 [SDOI2008]洞穴勘测 思路 没办法,我就是喜欢板子都想发的人 都是基础操作,不多说了 代码 #include <bits/stdc++.h> #define ls ch ...
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 动态树
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 3119 Solved: 1399[Submit] ...
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 (LCT)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2049 题面: 2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 1 ...
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 (动态树入门)
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1528 Solved: 644[Submit][ ...
- [BZOJ 2049] [Sdoi2008] Cave 洞穴勘测 【LCT】
题目链接:BZOJ - 2049 题目分析 LCT的基本模型,包括 Link ,Cut 操作和判断两个点是否在同一棵树内. Link(x, y) : Make_Root(x); Splay(x); F ...
随机推荐
- 2004: C语言实验——数日子(数组)
2004: C语言实验——数日子 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 213 Solved: 111[Submit][Status][Web ...
- a survey for RL
• A finite set of states St summarizing the information the agent senses from the environment at eve ...
- python - 辨识alert、window以及操作
selenium之 辨识alert.window以及操作 原创 2016年08月24日 11:01:04 4820 0 2 更多关于python selenium的文章,请关注我的专栏:Python ...
- js函数节流和函数防抖
概念解释 函数节流: 频繁触发,但只在特定的时间内才执行一次代码 函数防抖: 频繁触发,但只在特定的时间内没有触发执行条件才执行一次代码 函数节流 函数节流应用的实际场景,多数在监听页面元素滚动事件的 ...
- Pig Latin-freecodecamp算法题目
Pig Latin 1.要求 Pig Latin把一个英文单词的第一个辅音或辅音丛(consonant cluster)移到词尾,然后加上后缀 "ay". 如果单词以元音开始,你只 ...
- 二十一、C++中的临时对象
思考: 构造函数是一个特殊的函数 是否可以直接调用? 是否可以在构造函数中调用构造函数? 直接调用构造函数的行为是什么? 答: 直接调用构造函数将产生一个临时对象 临时对象的生命周期只有一条语句的时间 ...
- Pandas中数据的处理
有两种丢失数据 ——None ——np.nan(NaN) None是python自带的,其类型为python object.因此,None不能参与到任何计算中 Object类型的运算比int类型的运算 ...
- 01Qt中的隐式共享
隐式共享 隐式共享又称为回写复制(copy on write).当两个对象共享同一分数据时(通过浅拷贝实现数据共享),如果数据不改变,则不进行数据的复制.而当某个对象需要需要改变数据时,则进行深拷 ...
- navicat12.0.24破解方法,简单易操作,亲测可行
navicat12.0.24 32bit 链接:https://pan.baidu.com/s/1dakPje0AzwE86p6ZRHfnsQ 密码:f1ve 破解文件 链接:https://pan. ...
- $(MAKE) , make命令
make 定义了很多默认变量,像常用的命令或者是命令选项之类的,什么CC啊,CFLAGS啊之类.$(MAKE)就是预设的 make 这个命令的名称(或者路径).make -p 可以查看所有预定义的变量 ...