## Editorial for Mock CCC '18 Contest 2 S4 - A Tree Problem

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Imagine that there is a vertex incident on vertices and such that the two edges are the same color. The two subtrees of and assuming the tree is rooted at do not contain any good nodes.

If we check this for every pair of edges that have the same color, this gives us an solution.

We can improve this to linear-time by, instead of explicitly marking the nodes, keeping track implicitly of which subtrees are ineligible, and then DFSing in both directions to propagate which subtrees are blocked.

## Comments

Hot to "DFSing in both directions to propagate which subtrees are blocked" in .