bzoj2049: [Sdoi2008]Cave 洞穴勘测
lct入门题?
得换根了吧TAT
这大概不是很成熟的版本..
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cstdio>
- using namespace std;
- const int Maxn = ;
- int ch[Maxn][],p[Maxn],flip[Maxn];
- int n,m;
- const int D=;
- char in[D],out[*],*I=in,*O=out;
- #define gc (*I++)
- #define pc(x) ((*O++)=x)
- template <typename Q>
- void gt(Q&x) {
- static char c,f;
- for(c=gc,f=;!isdigit(c);c=gc)if(c=='-') f=;
- for(x=;isdigit(c);c=gc) x=x*+c-'';
- f && (x=-x);
- }
- template <typename Q>
- void pt(Q x){
- static char stk[];
- static int top;
- top=;
- if(x==) pc('');
- for(;x;x/=) stk[++top] = x%+'';
- for(;top;top--) pc(stk[top]);
- }
- void down(int x){
- if(flip[x]) {
- swap(ch[x][],ch[x][]);
- flip[ch[x][]]^=;
- flip[ch[x][]]^=;
- flip[x]=;
- }
- }
- bool isroot(int x){
- return ch[p[x]][]!=x && ch[p[x]][]!=x;
- }
- void rotate(int x) {
- int y=p[x],z=p[y];
- int l=ch[y][]==x,r=l^;
- if(!isroot(y)) ch[z][ch[z][]==y]=x;
- p[ch[x][r]]=y;
- p[y]=x;
- p[x]=z;
- ch[y][l]=ch[x][r];
- ch[x][r]=y;
- }
- int stk[Maxn],top;
- void splay(int x){
- stk[top=]=x;
- for(int t=x;!isroot(t);t=p[t]) stk[++top]=p[t];
- for(;top;top--) down(stk[top]);
- for(;!isroot(x);){
- int y=p[x],z=p[y];
- if(!isroot(y)){
- if( (ch[y][]==x)^(ch[z][]==y) )
- rotate(x);else rotate(y);
- }
- rotate(x);
- }
- }
- void access(int x){
- for(int t=;x;x=p[t=x]){
- splay(x);
- ch[x][]=t;
- }
- }
- int getroot(int x){
- for(access(x),splay(x);ch[x][];x=ch[x][]);
- return x;
- }
- void newroot(int x) {
- access(x);
- splay(x);
- flip[x]^=;
- }
- void cut(int x){
- access(x);
- splay(x);
- p[ch[x][]]=;
- ch[x][]=;
- }
- void combine(int x,int y) {
- newroot(x);
- p[x]=y;
- }
- void work() {
- gt(n),gt(m);
- char c;
- int a,b;
- for(int i=;i<=m;i++) {
- for(;c=gc,c!='Q' && c!='C' &&c!='D';);
- gt(a),gt(b);
- if(c=='Q') printf("%s\n",getroot(a)==getroot(b)?"Yes" : "No");
- else if(c=='C') combine(a,b);
- else newroot(a),cut(b);
- }
- }
- int main() {
- #ifdef DEBUG
- freopen("in.txt","r",stdin);
- freopen("out.txt","w",stdout);
- #endif
- fread(in,,D,stdin);
- work();
- return printf(out),;
- }
bzoj2049: [Sdoi2008]Cave 洞穴勘测的更多相关文章
- BZOJ2049 SDOI2008 Cave 洞穴勘测 【LCT】
BZOJ2049 SDOI2008 Cave 洞穴勘测 Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分 ...
- 【LCT】BZOJ2049 [SDOI2008]Cave 洞穴勘测
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 10059 Solved: 4863[Submit ...
- [BZOJ2049][Sdoi2008]Cave 洞穴勘测 LCT模板
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 9705 Solved: 4674[Submit] ...
- [bzoj2049][Sdoi2008]Cave 洞穴勘测_LCT
Cave 洞穴勘测 bzoj-2049 Sdoi-2008 题目大意:维护一个数据结构,支持森林中加边,删边,求两点连通性.n个点,m个操作. 注释:$1\le n\le 10^4$,$1\le m\ ...
- [BZOJ2049] [SDOI2008] Cave 洞穴勘测 (LCT)
Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...
- BZOJ2049: [Sdoi2008]Cave 洞穴勘测 Link-Cut-Tree 模板题
传送门 搞了这么长时间Splay终于可以搞LCT了,等等,什么是LCT? $LCT$就是$Link-Cut-Tree$,是维护动态树的一个很高效的数据结构,每次修改和查询的均摊复杂度为$O(logN) ...
- BZOJ2049——[Sdoi2008]Cave 洞穴勘测
1.题目大意:就是一个动态维护森林联通性的题 2.分析:lct模板题 #include <stack> #include <cstdio> #include <cstdl ...
- bzoj2049 [Sdoi2008]Cave 洞穴勘测 link cut tree入门
link cut tree入门题 首先说明本人只会写自底向上的数组版(都说了不写指针.不写自顶向下QAQ……) 突然发现link cut tree不难写... 说一下各个函数作用: bool isro ...
- bzoj2049: [Sdoi2008]Cave 洞穴勘测 lct裸题
题意:三种操作一种摧毁一条边,一种链接一条边,一种查询两个点是否联通 题解:lct的link和cut即可 /********************************************** ...
随机推荐
- npm不能安装任何包,报错:npm WARN onload-script failed to require onload script npm-autoinit/autoinit及解决方法
想要利用Hexo搭建一个博客,但是安装时npm一直报错,不仅仅是Hexo包,连别的其他包也不行,会提示下面的一堆错误 npm WARN onload-script failed to require ...
- 【BZOJ1050】【枚举+并查集】旅行comf
Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<30000).给你两个顶点S和T,求一条路径,使得路径上最大 ...
- CentOS 忘记root密码,解决方法
1.开机后,在倒数5秒结束前,按下任意键 2.在显示centos...的那个界面下,按e键(edit) 3.会出现三行的界面,选择中间 kernel...那行,然后按e键 4.在接着出现的那个界面最后 ...
- linux c静态链接库与动态链接库
库函数是我们编程的时候经常用到的,我们协作编程的时候可以将常用的函数封装成库供大家使用,这样能够提高大家的工作效率.对于库函数,它分为动态链接库和静态链接库.对于静态链接库我们必须是连接到可执行文件中 ...
- Linq/EF/lambda Group by/Order by 多个字段详细用法
1)单个字段Group by: //a.Key类型与a.Province字段类型一样 .GroupBy(a => a.Province).Select(a => a.Key).ToLis ...
- Egret 双端接入爱贝支付遇到的问题
首先要为 egret 工程引入第三方库: Egret 接第三方库:http://edn.egret.com/cn/index.php?g=&m=article&a=index& ...
- Github博客地址
欢迎访问我的Github博客: J.R.Smith_blog
- Reducing the Dimensionality of data with neural networks / A fast learing algorithm for deep belief net
Deeplearning原文作者Hinton代码注解 Matlab示例代码为两部分,分别对应不同的论文: . Reducing the Dimensionality of data with neur ...
- A Statistical View of Deep Learning (III): Memory and Kernels
A Statistical View of Deep Learning (III): Memory and Kernels Memory, the ways in which we remember ...
- ROR入门之旅
mac上为了不在登录画面看到其他账户,我禁用了root账户,而每次用Terminal的时候,先获得sudo账户的权限: sudo -s mac本身就安装有ruby ruby -v 查看当前安装的rub ...