Skip to content

Augmenting LinkCutTree doesn't seem to work #117

@tyilo

Description

@tyilo

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:

0 4
1 2
2 1
3 1

But instead I get:

0 2
1 1
2 1
3 1

The full code is available at https://gist.github.com/Tyilo/ebbbd06dcb02665c078ec3dac387c09a

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions