You are viewing a single comment's thread. Return to all comments →
A solution built on these lines passed all test cases:
Perform a depth-first search preprocessing step on the tree starting at the root (which is actually specified in the input). When first encountering a node, create a colour set that will contain all the colours in the subtree rooted at that node, add the colour of the node to this set, then process each child of the node.
Whenever you finish processing a node: