Graph Theory37 sections · 1633 units
Open in Course

Problem - Lomsat gelral

Codeforces 600E, Small-to-L...

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 {11, 11, 22, 33, 33, 33}, the most frequent color is 33 (appears 33 times), so the answer for that node is 33.

If there is a tie, sum all tied colors. There are up to 100100,000000 nodes. The standard approach is small-to-large merging (DSU on tree), which runs in O(nlogn)O(n \log n) total time.