LCT

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
namespace LinkCutTree{
	bool rev[MAXN+5];
	inline int max(register int a,register int b){return a>b?a:b;}
	int fa[MAXN+5],ch[MAXN+5][2],tp,s[MAXN+5];
	inline bool pan(register int u){return ch[fa[u]][1]==u;}
	inline bool IsRoot(register int u){return (ch[fa[u]][0]!=u&&ch[fa[u]][1]!=u);}
	inline void PushUp(register int u){
		return ;
	}
	void PushDown(int u){
		if(rev[u])
			swap(ch[u][0],ch[u][1]),rev[ch[u][0]]^=1,rev[ch[u][1]]^=1,rev[u]=0;
		return ;
	}
	inline void Rotate(int x){
		register int y=fa[x],z=fa[y],dx=pan(x),dy=pan(y),w=ch[x][dx^1];
		if(!IsRoot(y)) ch[z][dy]=x;
		ch[x][dx^1]=y,ch[y][dx]=w;
		if(w) fa[w]=y;
		fa[y]=x,fa[x]=z;
		PushUp(y);
		return ;
	}
	inline void Splay(int x){
		int tp=0,y=x;
		s[++tp]=x;
		while(!IsRoot(y)) s[++tp]=y=fa[y];
		while(tp) PushDown(s[tp--]);
		for(int y=fa[x];!IsRoot(x);Rotate(x),y=fa[x])
			if(!IsRoot(y))
				Rotate(pan(x)==pan(y)?y:x);
		PushUp(x);
		return ;
	}
	inline int Access(int x){
		int y=0;
		while(x)
			Splay(x),ch[x][1]=y,PushUp(x),y=x,x=fa[x];
		return y;
	}
	void MakeRoot(int x){
		Access(x),Splay(x);
		rev[x]^=1;
		return ;
	}
	int FindRoot(int x){
		Access(x),Splay(x);
		while(ch[x][0]) PushDown(x),x=ch[x][0];
		Splay(x);
		return x;
	}
	void Link(int x,int y){
		MakeRoot(x);
		if(FindRoot(y)!=x) fa[x]=y;
		return ;
	}
	void Cut(int x,int y){
		
		MakeRoot(x),Access(y),Splay(y);
		if(ch[y][0]==x&&!ch[x][1])
			ch[y][0]=0,fa[x]=0,PushUp(y);
		/*
		MakeRoot(x);
		if(FindRoot(y)==x&&fa[y]==x&&!ch[y][0])
			fa[y]=ch[x][1]=0,PushUp(x);//also right
		*/
		return ;
	}
	void Split(int x,int y){
		MakeRoot(x);
		Access(y),Splay(y);
		return ;
	}
}
using namespace LinkCutTree;
struct Edge{
	int v,nxt;
}edge[2*MAXN+5];
int ecnt,head[MAXN+5];
inline void Addedge(int u,int v){
	edge[++ecnt]=(Edge){v,head[u]},head[u]=ecnt;
	edge[++ecnt]=(Edge){u,head[v]},head[v]=ecnt;
	return ;
}
void DFS(int u){
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		if(v==fa[u]) continue;
		fa[v]=u,DFS(v);
	}
	return ;
}
int main(){
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值