LCT*3
struct LCT{
#define lch V[p].son[0]
#define rch V[p].son[1]
#define Son(p) (V[V[p].fa].son[1]==p)
#define Isroot(p) (V[V[p].fa].son[0]!=p && V[V[p].fa].son[1]!=p)
struct Ver{int siz,son[2],fa,t1;}V[maxn];
int tot;
int New(int x,int fa){++tot;V[tot].fa=fa;V[tot].siz=1;return tot;}
void Pushup(int p){V[p].siz=V[lch].siz+V[rch].siz+1;}
void Upt1(int p){swap(lch,rch);V[p].t1^=1;}
void Pushdown(int p){if(V[p].t1)Upt1(lch),Upt1(rch);V[p].t1=0;}
void Spread(int p){if(!Isroot(p))Spread(V[p].fa);Pushdown(p);}
void Rotate(int p){
int f=V[p].fa,lf=V[f].fa,s=Son(p),ls=Son(f);
if(!Isroot(f))V[lf].son[ls]=p;
V[p].fa=lf;
V[f].son[s]=V[p].son[s^1],V[V[p].son[s^1]].fa=f;;
V[p].son[s^1]=f,V[f].fa=p;
Pushup(f),Pushup(p);
}
void Splay(int p){
Spread(p);
for(int f=V[p].fa;!Isroot(p);Rotate(p),f=V[p].fa)
if(!Isroot(f))Rotate(Son(f)==Son(p) ? f : p);
}
void Access(int x){int p;for(p=0;x;p=x,x=V[x].fa)Splay(x),V[x].son[1]=p,Pushup(x);}
void Makeroot(int x){Access(x),Splay(x),Upt1(x);}
int Findroot(int p){Access(p),Splay(p),Pushdown(p);while(lch)p=lch,Pushdown(p);Splay(p);return p;}
void Link(int x,int y){if(Findroot(x)==Findroot(y))return;Makeroot(x),V[x].fa=y;}
void Split(int x,int y){Makeroot(x),Access(y),Splay(y);}
void Cut(int x,int y){Split(x,y);if(V[y].son[0]==x && V[x].son[1]==0)V[y].son[0]=V[x].fa=0;Pushup(y);}
}L;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现