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