You are given an edge-weighted tree T=(V,E) with ∣V∣=n vertices labeled through 1,2,…,n where each vertex i has a value ai.
You need to select a subset S⊆V of at mostk vertices with distinct values. You want to maximize the sum of weights of "spanned" edges, where an edge e is "spanned" if and only if there exists u,v∈S such that e lies on the only path between u and v.
输入格式
The first line contains two integers n,k(1≤n≤5000,2≤k≤5), denoting the size of the tree and the maximum size of the subset you need to choose, respectively.
The second line contains n integers a1,a2,...,an(1≤ai≤n), denoting the value of each vertex.
Then n−1 lines follow, where each line contains 3 integers u,v,w(1≤u,v≤n,−109≤w≤109), denoting there is an edge (u,v) with weight w in the tree.
输出格式
Output an integer in a line, denoting the maximized sum of weights of "spanned" edges.