You are given a tree where each node has a color (an integer). For each node v, find the sum of all colors that appear most frequently in v's subtree. Example: if the subtree has colors {, , , , , }, the most frequent color is (appears times), so the answer for that node is .
If there is a tie, sum all tied colors. There are up to , nodes. The standard approach is small-to-large merging (DSU on tree), which runs in total time.