Problem: You are given a tree, which consists of vertices. Recall that a tree is a connected undirected graph without cycles.
Example of a tree.
Vertices are numbered from to . All vertices have weights, the weight of the vertex is .
Recall that the distance between two vertices in the tree is the number of edges on a simple path between them.
Your task is to find the subset of vertices with the maximum total weight (the weight of the subset is the sum of weights of all vertices in it) such that there is no pair of vertices with the distance or less between them in this subset.
Input Format: The first line of the input contains two integers and () — the number of vertices in the tree and the distance restriction, respectively.
The second line of the input contains integers (), where is the weight of the vertex .
The next lines contain edges of the tree. Edge is denoted by two integers and — the labels of vertices it connects (, ).
It is guaranteed that the given edges form a tree.
Output Format: Print one integer — the maximum total weight of the subset in which all pairs of vertices have distance more than .