Say you want to count distinct colors in each subtree. For a node , you need all colors from all children, plus 's own color. You could maintain a set for each node. After processing children, merge all child sets into one set for . The result contains all colors in 's subtree. The question: how do you merge sets efficiently when there are many children and large sets?
If you pick the wrong merge order, you will copy the same elements over and over.