You need to track the current maximum frequency while merging. When you merge a color from a smaller child's map, check if its new count exceeds the current max. If it does, update the max and reset the sum to this color's value.
If it equals the max, add the color to the sum. After processing all children and adding 's color, you have the max frequency and the sum of all colors at that frequency. This is your answer for node .