bzoj 2049: [Sdoi]Cave 洞穴探测 (LCT)
第一次写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)的更多相关文章
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 (LCT)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2049 题面: 2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 1 ...
- 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 洞穴勘测——LCT
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2049 省选之前来切一道数据结构模板题. 题意 这是一道模板题. N个点,M次操作,每次加边/ ...
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 (LCT维护连通性)
直接把x设为根,然后查询y所在联通块的根是不是x就行了. CODE #include <cstdio> #include <cstring> #include <algo ...
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘測 LCT
入门级LCT: 仅仅有 Cut Link 2049: [Sdoi2008]Cave 洞穴勘測 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 3073 ...
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 (动态树入门)
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1528 Solved: 644[Submit][ ...
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 动态树
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 3119 Solved: 1399[Submit] ...
- [BZOJ 2049] [Sdoi2008] Cave 洞穴勘测 【LCT】
题目链接:BZOJ - 2049 题目分析 LCT的基本模型,包括 Link ,Cut 操作和判断两个点是否在同一棵树内. Link(x, y) : Make_Root(x); Splay(x); F ...
- bzoj 2049 [Sdoi2008]Cave 洞穴勘测(LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2049 [题意] 给定森林,可能有连边或断边的操作,回答若干个连通性的询问. [思路] ...
随机推荐
- JMeter-显示调试日志log
JMeter-调试日志记录 参考文档:https://jmeter.apache.org/usermanual/hints_and_tips.html 大多数测试元素包括调试日志记录. 如果从GUI运 ...
- Spark学习之路 (二十)SparkSQL的元数据[转]
概述 SparkSQL 的元数据的状态有两种: 1.in_memory,用完了元数据也就丢了 2.hive , 通过hive去保存的,也就是说,hive的元数据存在哪儿,它的元数据也就存在哪儿. 换句 ...
- collection和map集合类知识点总结
collection和map集合类知识点总结 最近在准备java基础知识的总结,发现对于集合类的知识点很多很杂,借鉴网上的帖子,整理如下. 一.定义 集合框架是为表示和操作集合而规定的一种统一的标准的 ...
- 论文阅读笔记(七)【TIP2018】:Video-Based Person Re-Identification by Simultaneously Learning Intra-Video and Inter-Video Distance Metrics
是由一篇 IJCAI2016 扩的期刊. 该篇会议论文的阅读笔记[传送门] 期刊扩充的部分:P-SI2DL 1.问题描述: 在会议论文中介绍的SI2DL方法采用了视频三元组作为视频关系(是否匹配)的逻 ...
- linux 搭建python虚拟环境
requirements.txt 包含paramiko,pysfp.setuptools,适用python版本3.6.6+ 前提编译安装python wget wget https://www.pyt ...
- C#索引器学习笔记
本笔记摘抄自:https://www.cnblogs.com/ArmyShen/archive/2012/08/27/2659405.html,记录一下学习过程以备后续查用. 索引器允许类或者结构的实 ...
- MySql快速入门(四)
在之前我们对MySql已经有了基本的了解,接下来我们就来接触MySql的分库分表,请往下阅读: 分库分表之MyCat实现 分库分表介绍: 随着微服务这种架构的兴起,我们应用从一个完整的大的应用,切分为 ...
- pod has unbound immediate PersistentVolumeClaims : statefulset挂载不上pv的另一种情况
大家都直到当volumeClaimTemplates匹配不上pv时,会出现statefulset挂载不到pv的问题.错误提示如下: error while running "VolumeBi ...
- 《操作系统真象还原》bochs安装
在安装bochs之前,我们先需要安装虚拟机和linux发行版,也可以安装双系统,总之有个linux操作系统就好. 我是在ubuntu14.04系统下安装bochs的. 安装Bochs 以下为安装步骤 ...
- Android Studio阶段性学习总结_1
这半个月一直在学习Android方面的知识,对Android开发有了一个基本的认识,学会了Android studio的基本操作. 在建立第一个Android studio项目时,我遇到了很大的阻碍, ...