Royal Tax

Given a tree of cities, each with tax gold and a carriage of capacity C, find the minimum total distance to collect all gold into the capital vault.

Hard8TreeDynamic programmingDFSGreedyNo attempts yetTime limit1sMemory limit1024 MB

Problem

The kingdom of Nlogônia is rich and its people are educated and content, but the King is a tyrant when the subject is taxes. At the end of every year, each city of the kingdom owes a fixed amount of gold in taxes. When collection time arrives, the King sends the royal carriage along the roads of the kingdom to gather the gold that is owed.

Each road connects two different cities and can be driven in both directions. The road network lets the carriage reach any city from any other city, possibly through intermediate cities, and there is exactly one path between two different cities.

Every city has a royal vault that stores tax gold. The vaults are enormous, so each one can hold all the gold owed by the entire kingdom. The carriage leaves the capital, drives the roads and visits cities to load the gold they owe. If that helps, it may leave part of the collected gold in any royal vault for a while. When the collection ends, all the gold owed by all the cities must be stored in the vault of the capital.

You are given the amount of gold each city owes in kg, the list of roads with their lengths in km, and the carrying capacity of the royal carriage in kg. Determine the minimum distance the carriage has to travel to collect all the gold that is owed.

Input

The first line contains two integers NN and CC, the number of cities and the carrying capacity of the carriage (2N1042 \le N \le 10^4, 1C1001 \le C \le 100). The capital is city 1 and the other cities are numbered from 2 to NN.

The second line contains NN integers E1,E2,,ENE_1, E_2, \dots, E_N, where EiE_i is the amount of gold city ii owes, in kg (0Ei1000 \le E_i \le 100).

Each of the next N1N-1 lines contains three integers AA, BB and LL, meaning that a road of length LL km connects city AA and city BB (1A,BN1 \le A, B \le N, ABA \ne B, 1L1001 \le L \le 100).

Output

Print on the first line a single integer, the minimum distance in km that the royal carriage has to travel to collect all the tax that is owed.