//#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;
}
LCT
最新推荐文章于 2022-04-06 23:00:19 发布