Call a Meeting

Limits: 4s, 512 MB

Alice and Bob are hosting a programming contest in Abiland. All the judges live in different cities (or same). On the contest day, all judges are going to be present at contest venue. Alice and Bob will pay the travel cost of all the judges. They want to minimize total traveling cost. Cities are connected by roads like a tree. Judges can move alone or can form a group with other judges. Cost of the traveling between cities depends on the size of the group. Two groups can merge. After merging, all members of previous two group will be in the new group. If two judges are in the same group at some point then they will be in same group forever.

This is a companion discussion topic for the original entry at