## Editorial for LCC/Moose '18 Contest 3 S4 - Christmas Tree

**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.**

Author:

We want colourful subtrees in the tree, and that the colours in each of the subtrees is distinct. Thus, we can greedily choose the smallest subtrees to make colourful. We can show this works because if we choose any subtree that is larger than the smallest subtree, we need more colours, which is counter-intuitive.

The algorithm goes like this: Do a depth-first search (DFS) starting from the root , each time inserting into an array the size of its subtree (the number of vertices in its children and itself). Then we can sort the array, and the answer is the element in the array ( indexed).

**Time Complexity: **

Note: Some programmers who do contests on CodeForces may see that this problem is very similar to this problem. In fact, the algorithm is the exact same. This problem was actually inspired by the CodeForces problem.

## Comments