You are given a tree with camps, numbered from to .
Camp initially contains bags of sand and workers. During the process, a camp may also contain sand and workers moved from other camps.
Camp is the central camp and cannot be closed. In one operation, you may choose any other camp that is currently a leaf. Let be its only neighbor. You move all the sand and all the workers from to , and then close camp .
Every worker moved from must inspect every bag of sand at after the move. Therefore, if immediately before the operation the two camps contain bags of sand and workers, the cost of the operation is
Afterwards, camp contains bags of sand and workers.
Continue until only camp remains. Find the minimum possible total cost.
Camp must first be moved to camp , which costs . Camp then contains bags and workers, so moving it to camp costs .
One optimal order is . The four operations cost , , , and , for a total of .
One optimal order is . The five operations cost , , , , and , for a total of .
Camp is already the only camp, so no operation is performed.
Closing camps , , and in this order costs , , and , respectively. No other order has a smaller total cost, so the answer is .