Logistical Warehouse

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

ICP(International Carrier Products) Company plans to build new kk logistical warehouses in order to facilitate the efficient delivery of products. Before being delivered to the target location, the products are stored at a logistical warehouse. Then these products are delivered to the final location for distribution. The locations of logistical warehouses are very important in optimizing delivery time and space of warehouse logistics.

Imagine that the chain for supply and management is given as a tree T=(V,E)T = (V, E). Each node v_iv\_i of TT has weight w_iw\_i, and each edge e_je\_j of TT has an integer length l_jl\_j. For a point pp in an edge, the distance from a node v_iv\_i to pp is defined to be w_i × π(v_i,p)w\_i \times |\pi(v\_i, p)|, where π(v_i,p)\pi(v\_i, p) is the path connecting v_iv\_i and pp in TT and π(v_i,p)|\pi(v\_i, p)| is the sum of the lengths of segments (edges) in π(v_i,p)\pi(v\_i, p).

We want to choose kk points on the edges of TT as centers under the following restriction: each center lying on an edge ee must be a point at an integer distance from each endpoint of ee. Observe that centers are allowed to lie on nodes. For instance, if the length of ee is 33, we can choose a center among the following four points: the two endpoints of ee and the two points on ee at distance 11 from the endpoints of ee.

The goal is to choose kk centers on the edges of TT such that the maximum distance from a node to its closest center is minimized. We call a set of such kk centers an optimal set of kk centers for this problem.

For example, figure (a) shows a tree with four nodes of weights 33, 33, 11, 22 labelled next to the vertices, and three edges with lengths 22, 33, 22 labelled next to the edges. Centers are allowed to lie on the nodes and the small gray squares. If we choose three centers among them, an optimal solution is shown in the black squares of figure (b) with the maximum distance 22.

(a)(b)

Given a tree T=(V,E)T = (V, E) of nn nodes with weights and n1n - 1 edges with integer lengths, write a program to output the maximum distance from a node to its closest center in an optimal set of kk centers.

입력

Your program is to read from standard input. The input starts with a line containing two integers nn and kk (1kn200,0001 \le k \le n \le 200,000), where nn is the number of nodes in a tree and kk is the number of centers to choose. Then there are n1n-1 edges in the tree. The nodes are numbered from 11 to nn, and the edges are numbered from 11 to n1n-1. The next line contains nn positive integers such that the ii-th integer represents the weight of the ii-th node. The weights are no more than 10610^6. In the following n1n-1 lines, the ii-th line contains three positive integers. The first two integers represent the two indices of the nodes at the endpoints of the ii-th edge. The third integer represents the length of the ii-th edge. The lengths are no more than 10610^6.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the maximum distance from a node to its closest center in an optimal set of kk centers.