It's really worthless
After the boss finished talking about the basics of LCT, Gao asked a question. as follows.
The cut operation was originally like this
void cut(int x,int y)
{
makeroot(x);
ac(y);
putdown(x);
splay(y); <<<<<<<这里
putdown(y);
par[ls[y]]=fa[ls[y]]=0;
lson[y]=0;
}
But as the arrow points, why splay this point?
After modification, it looks like this:
void cut(int x,int y)
{
makeroot(x);
ac(y);
putdown(x);
par[y]=fa[y]=0;
rson[x]=0;
}
It feels like it's okay, because x, y are connected.
past the example. submit.
Then it's RE. For the original function, you can AC.
why?I feel so retarded.
"x, y are connected." That's the problem.
for example. A splay (auxiliary tree) is shown in the figure, the red is the x point. Actually point y (blue) is in the right subtree of point x, not the right child.
Think carefully, since this splay tree is built with depth as the key, then the y point should be the successor and not the son of the x point.
In short, in splay (auxiliary tree), the two points x and y are not connected. I can pass the sample only because the sample is too watery, and the successor is the right son. . .