You are given a computer network with n nodes. The network is an undirected tree, and edge i connects node ai and node bi with length ci.
Every node holds one data item of its own, and the item on node j has size sj. A user delivers any item to any node. The delivery cost is the size of the item times the distance the item travels, and the data always follows the shortest path.
Once a delivery finishes, every node on that path, including the destination, caches the item. From the next delivery on, the item is sent by the node closest to the destination among the nodes that cache it, so the cost is the original size times the distance from that node to the destination. Nothing is cached at the start, so item j sits only on node j.
The user chooses the item and the destination freely for every delivery. If the destination already caches the item, the distance is 0 and the cost is 0 as well. Find the largest total cost of m deliveries.