Graph Theory37 sections · 1633 units
Open in Course

Lomsat gelral - Observation

(Frequency tracking)

For each subtree, you need a map: color → count. You also need to track which colors have the maximum count in that subtree. After merging child maps, update the frequency of vv's color. Then find all colors with max frequency and sum their values.

Merging maps directly would be slow without small-to-large. You would copy large maps repeatedly. The technique keeps it fast by merging small maps into the large one.