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 to Node and modified Node::fix() to contain:
void fix() {
sz = 1;
if (c[0]) {
c[0]->p = this;
sz += c[0]->sz;
}
if (c[1]) {
c[1]->p = this;
sz += c[1]->sz;
}
// (+ update sum of subtree elements etc. if wanted)
}
My test code is
LinkCut T(4);
T.link(1, 0);
T.link(2, 1);
T.link(3, 0);
rep(i, 0, 4) {
cout << i << " " << T.node[i].sz << "\n";
}
I would expect the output to be:
But instead I get:
The full code is available at https://gist.github.com/Tyilo/ebbbd06dcb02665c078ec3dac387c09a
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 toNodeand 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