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. Python Select模型

    IO多路复用 IO多路复用就是我们经常说的select epoll.select和epoll的好处是单个process就可以同时处理多个网络IO.基本原理是select\epoll会不断的轮询所负责的 ...

  2. 【胎教】做AI的基础,开始学习。

    昨天,找了博导,他给我聊了一下暑假任务.现总结如下: 1. 周志华, 机器学习: 2. GoodFellow,深度学习: 3. 曾更生,*****医学图像处理: 4. cs231n,公式推导,课后习题 ...

  3. 20180901 JavaScript闭包和匿名函数自动调用

    引用: 1. JavaScript闭包_by runoob 2. JS中(function(){xxx})这么写是什么意思? (一)闭包是可以访问上一层函数作用域里变量的函数,即便上一层函数已经关闭. ...

  4. 【转】MFC 程序入口和执行流程

    一 MFC程序执行过程剖析 1)我们知道在WIN32API程序当中,程序的入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用 ...

  5. centos6启动故障排除

    centos6中boot文件被全部删除的故障排除 /boot文件里关于启动的核心文件有三个,/vmlinuz-2.6.32-696.e16.x86_64,initramfs-2.6.32-696.el ...

  6. Vim编辑器基础

    Vim编辑器基础 vi:Visual Interface vim:VI iMproved Vim模式 1.编辑模式(命令模式) 只能下达命令,不能键入字符 2.输入模式 键入字符 3.末行模式 左下角 ...

  7. 一个炫酷的flash网站模板

    这是一个炫酷的flash欧美网站模板,它包括首页,公司简介,留言等五个页面,界面转换非常的炫酷!他还有时间.全屏.背景音乐开关的功能!有兴趣的朋友可以看看!贴几张网站图片给大家看看! 下载后直接找到s ...

  8. LeetCode(154) Find Minimum in Rotated Sorted Array II

    题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...

  9. SQL_2_查询Select语句的使用

    查询一词在SQL中并不是很恰当,在SQL中查询除了向数据库提出问题之外,还可以实现下面的功能: 1>建立或删除一个表 2>插入.修改.或删除一个行或列 3>用一个特定的命令从几个表中 ...

  10. Chromium Embedded Framework

    关于CEF 近期由于工作需要开始研究了Google的Chromium Embedded Framework(CEF),这是一个基于Google Chromium开源代码的项目,使用CEF可以很方便的在 ...