Getting Started with trees heuristic merge

Foreword

Tree heuristic merger, namely \ (the DSU \ ON \ Tree \) , is a very easy to use, very practical method of tree maintenance information.

Because it is relatively simple, easy to understand, so here simply record it.

Pre-knowledge: Heavy son

What is the weight of his son?

This should be a tree chain split a concept of it. Heavy son is a child node of a node, the largest sub-tree node size.

Applicable

You can easily point to each contracted white and black, respectively, and you need to have a black node, the child node tree white outer situation within its subtree for each point.

Implementation

This is a greedy process.

Consider \ (dfs \) traversal, for each son of the current point, other than the son of the last operation, all remaining son we have it all points within the sub-trees are dyed white to black and then again Black (middle dye white to handle other son).

And that son last operation, we do not need to after Black dyed white, so we choose the inevitable heavy greedy son last operation.

Then just fine.

Guess you like

Origin www.cnblogs.com/chenxiaoran666/p/DSU_on_Tree.html