[SDOI2008] bzoj 2049 Cave洞穴勘测 - LCT学习笔记

64 篇文章 0 订阅
40 篇文章 0 订阅

屯板子,LCT的话Menc讲的就不错

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 10010
using namespace std;
int rev[N],fa[N],pf[N],ch[N][2];
inline int setc(int x,int y,int z)
{
    if(!x) return fa[y]=0;
    ch[x][z]=y;if(y) fa[y]=x;
    return 0;
}
inline int gw(int x)
{
    return ch[fa[x]][1]==x;
}
inline int rotate(int x)
{
    int y=fa[x],z=fa[y],a=gw(x),b=gw(y),c=ch[x][a^1];
    return swap(pf[x],pf[y]),setc(y,c,a),setc(x,y,a^1),setc(z,x,b);
}
inline int push_down(int x)
{
    if(!rev[x]) return 0;
    swap(ch[x][0],ch[x][1]);
    if(ch[x][0]) rev[ch[x][0]]^=1;
    if(ch[x][1]) rev[ch[x][1]]^=1;
    return rev[x]=0;
}
inline int all_down(int x)
{
    if(fa[x]) all_down(fa[x]);
    if(rev[x]) push_down(x);
    return 0;
}
inline int splay(int x)
{
    all_down(x);
    while(fa[x])
    {
        if(fa[fa[x]])
        {
            if(gw(x)^gw(fa[x])) rotate(x);
            else rotate(fa[x]);
        }
        rotate(x);
    }
    return 0;
}
inline int expose(int x)
{
    splay(x);int c=ch[x][1];
    if(c) fa[c]=0,pf[c]=x,ch[x][1]=0;
    return 0;
}
inline int splice(int x)
{
    splay(x);int y=pf[x];if(!y) return false;
    expose(y),splay(y),setc(y,x,1),pf[x]=0;
    return true;
}
inline int access(int x)
{
    expose(x);while(splice(x));return 0;
}
inline int evert(int x)
{
    return access(x),splay(x),rev[x]^=1;
}
inline int link(int x,int y)
{
    return evert(y),splay(y),pf[y]=x;
}
inline int cut(int x,int y)
{
    evert(x),access(y),splay(x);
    if(ch[x][1]==y) pf[y]=fa[y]=ch[x][1]=0;
    return 0;
}
inline int get_r(int x)
{
    access(x),splay(x);
    while(ch[x][0]) x=ch[x][0];
    return splay(x),x;
}
inline int connected(int x,int y)
{
    return get_r(x)==get_r(y);
}
char opt[100];
#define gc getchar()
inline int inn()
{
    int x,ch;while((ch=gc)<'0'||ch>'9');
    x=ch^'0';while((ch=gc)>='0'&&ch<='9')
        x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    while(m--)
    {
        scanf("%s",opt);
        if(opt[0]=='C') link(inn(),inn());
        else if(opt[0]=='D') cut(inn(),inn());
        else printf("%s\n",connected(inn(),inn())?"Yes":"No");
    }
    return n-n;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值