Freezing Trees

We heard you like trees. But this problem has no relation to trees being frozen. :D

You are given a rooted tree with $n$ nodes. The node with index $1$ is the root. Although the tree is not frozen, the tree is colorful. Each of the nodes is colored with a color identified by an integer from $1$ to $m$.


This is a companion discussion topic for the original entry at https://toph.co/p/freezing-trees