Open tyilo opened 5 years ago
Ugh. I don't understand the link-cut tree well enough to say what's going wrong. We should replace it by a better version... (#63)
In general, I think for data structures that can be augmented, like segtrees or (as we recently learned) Link Cut Trees, we should try to separate the code that's meant to be augmented from the rest of the code.
@Tyilo you might need to maintain the size of virtual children as well, see Benq's implementation: LCT.h#L27, example problem: https://codeforces.com/contest/1681/problem/F
I have tried to augment LinkCutTree with the subtree size, however I can't get it to work.
I have added
int sz = 1;
as a field toNode
and modifiedNode::fix()
to contain:My test code is
I would expect the output to be:
But instead I get:
The full code is available at https://gist.github.com/Tyilo/ebbbd06dcb02665c078ec3dac387c09a