access
void access(int x) {
int y=0;
while (x) {
splay(x,0);
f[t[x][1]]=0;p[t[x][1]]=x;
t[x][1]=y;f[y]=x;p[y]=0;
updata(x);
y=x;x=p[x];
}
}
makeroot
void makeroot(int x) {
access(x);splay(x,0);rev[x]^=1;
}
link
void link(int x,int y) {
makeroot(x);p[x]=y;
}
cut
void cut(int x,int y) {
makeroot(x);access(y);splay(y,0);
t[y][0]=0;f[x]=p[x]=0;
updata(y);
}