Problem: You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.

You are given m queries. The i-th query is given as an integer q_i. In this query you need to calculate the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by three integers u_i, v_i and w_i — the labels of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) and the weight of the edge (1 ≤ w_i ≤ 2 ⋅ 10^5). It is guaranteed that the given edges form a tree.

The last line of the input contains m integers q_1, q_2, ..., q_m (1 ≤ q_i ≤ 2 ⋅ 10^5), where q_i is the maximum weight of an edge in the i-th query.

Output

Print m integers — the answers to the queries. The i-th value should be equal to the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Queries are numbered from 1 to m in the order of the input.

Examples

Input


7 5
1 2 1
3 2 3
2 4 1
4 5 2
5 7 4
3 6 2
5 2 3 4 1


Output


21 7 15 21 3 


Input


1 2
1 2


Output


0 0 


Input


3 3
1 2 1
2 3 2
1 3 2


Output


1 3 3 

Note

The picture shows the tree from the first example: <image>

Solution (in JAVA):

Solution:
/*input
 

1 2
1 2




 
*/
import java.io.*;
import java.util.*;
 
 
 
 
public class mymy
{
	
 
	static OutputStream outputStream = System.out;
	static PrintWriter out = new PrintWriter(outputStream);
	static InputStream inputStream = System.in;
	static InputReader br = new InputReader(inputStream);
 
 
	// static BufferedReader br;
	// static BufferedWriter out;

	static class dsu
	{
		int [] par;
		long[] size;
		long pairs=0;
		dsu(int n)
		{
			par=new int[n];size=new long[n];
			for(int i=0;i<n;i++)
			{
				size[i]=1;par[i]=i;
			}
			pairs=0;
		}
		void merge(int x,int y)
		{
			int parx=find(x),pary=find(y);
			if(parx==pary) return;
			long min1=(size[parx]*(size[parx]-1))/2;
			long min2=(size[pary]*(size[pary]-1))/2;
			if(size[parx]>size[pary])
			{
				par[pary]=parx;size[parx]+=size[pary];
				pairs+=(size[parx]*(size[parx]-1))/2;
			}
			else
			{
				par[parx]=pary;size[pary]+=size[parx];
				pairs+=(size[pary]*(size[pary]-1))/2;
			}
			pairs-=min2+min1;
		}
		int find(int x)
		{
			if(par[x]==x)
				return x;
			else
				return find(par[x]);
		}
	}

	static class node implements Comparable<node>
	{
		int l,r;int weight;
	
		node(int i,int o,int w)
		{
			l=i;r=o;weight=w;
		}
		public int compareTo(node n)
		{
			if(this.weight!=n.weight) return this.weight-n.weight;
			return this.l-n.l;
		}
	}

	static class query implements Comparable<query>
	{
		int data;int indx;
	
		query(int i,int o)
		{
			data=i;indx=o;
		}
		public int compareTo(query n)
		{
			if(this.data!=n.data) return this.data-n.data;
			return this.indx-n.indx;
		}
	}
 
	public static void main(String[] args)throws IOException
	{
		// br=new BufferedReader(new FileReader("deposits.in"));


		int n=br.nextInt();
		int q=br.nextInt();

		node[] a=new node[n-1];
		query[] quer=new query[q];

		long[] ans=new long[q];

		for(int i=0;i<n-1;i++)
		{
			int l=br.nextInt()-1;
			int r=br.nextInt()-1;
			int w=br.nextInt();

			a[i]=new node(l,r,w);
		}

		for(int i=0;i<q;i++)
		{
			quer[i]=new query(br.nextInt(),i);
		}

		Arrays.sort(a);
		Arrays.sort(quer);

		int i=0,j=0;

		dsu dsu=new dsu(n);

		i=0;

		while(i<n-1 && j<q)
		{
			if(a[i].weight<=quer[j].data)
			{
				dsu.merge(a[i].l,a[i].r);
				i++;
			}
			else
			{
				ans[quer[j].indx]=dsu.pairs;
				j++;
			}
		}
		while(j<q)
		{
			ans[quer[j].indx]=dsu.pairs;
			j++;
		}

		for(i=0;i<q;i++) out.print(ans[i]+" ");

		out.println();



		
 
		out.close();
 
	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
 
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
 
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
 
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
 
	}
	
}