Content Delivery

Pick an item and destination for each of m deliveries on a weighted tree with path caching to maximize total size times travel distance.

Hard8Dynamic programmingTreeGreedyNo attempts yetTime limit5sMemory limit256 MB

Problem

You are given a computer network with nn nodes. The network is an undirected tree, and edge ii connects node aia_i and node bib_i with length cic_i.

Every node holds one data item of its own, and the item on node jj has size sjs_j. 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 jj sits only on node jj.

The user chooses the item and the destination freely for every delivery. If the destination already caches the item, the distance is 00 and the cost is 00 as well. Find the largest total cost of mm deliveries.

Input

The first line contains the number of nodes nn and the number of deliveries mm. (2n20002 \le n \le 2000, 1m1091 \le m \le 10^9)

Each of the next n1n-1 lines contains one edge as aia_i, bib_i, cic_i in this order. (1ai,bin1 \le a_i, b_i \le n, 1ci100001 \le c_i \le 10000)

The next line contains nn integers. The jj-th integer is the size sjs_j of the item on node jj. (1sj100001 \le s_j \le 10000)

The given network is always a tree.

Output

Print the maximum total cost of the mm deliveries on one line.