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:
import java.io.*;
import java.math.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.Comparator.*;

public class Main {
    FastScanner in;
    PrintWriter out;
    ArrayList<Integer>[] graph;
    ArrayList<GraphPair>[] weightedGraph;
    long mod = (long) 1e9 + 7; // 998_244_353L || (long) 1e9 + 9
    boolean multitests = false;

    private void solve() throws IOException {
        // solveA();
        // solveB();
        // solveC();
        // solveD();
        // solveE();
        // solveF();
        solveG();
    }

    private void solveA() throws IOException {
        int n = in.nextInt(), k = 0;
        for (int i = 0; i < n; i++)
            if ((in.nextInt() & 1) == 0)
                k++;
        out.println(min(k, n - k));
    }

    private void solveB() throws IOException {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int[] st = new int[n];
        int ss = 0;
        for (int i = 0; i < n; i++) {
            while (ss > 0 && st[ss - 1] > a[i])
                ss--;
            st[ss++] = a[i];
        }
        out.println(n - ss);
    }

    private void solveC() throws IOException {
        long n = in.nextLong(), m = in.nextLong();
        long[] sum = new long[10];
        for (int i = 0; i < 10; i++)
            sum[i] = ((i == 0 ? 0 : sum[i - 1]) + m) % 10;
        for (int i = 0; i < 10; i++)
            sum[i] += (i == 0 ? 0 : sum[i - 1]);
        out.println(sum[9] * (n / (m * 10)) + ((n % (m * 10)) / m > 0 ? sum[(int) ((n % (m * 10)) / m) - 1] : 0));
    }

    private void solveD() throws IOException {
        int n = in.nextInt(), k = in.nextInt();
        int[] a = in.nextIntArray(n);
        shuffleInt(a);
        sort(a);
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < 20; i++) {
            int[] cnt = new int[1 << i], sum = new int[1 << i];
            for (int j = 0; j < n; j++) {
                int x = a[j], cntr = 0;
                while (x >= (1 << i)) {
                    x >>= 1;
                    cntr++;
                }
                cnt[x]++;
                sum[x] += cntr;
                if (cnt[x] == k)
                    ans = min(ans, sum[x]);
            }
        }
        out.println(ans);
    }

    private void solveE() throws IOException {
        int n = in.nextInt();
        TreeSet<String> blocked = new TreeSet<>();
        for (int i = 0; i < 2; i++)
            blocked.add(in.next());

        out.println("YES");

        if (!blocked.contains("ab") && !blocked.contains("bc") && !blocked.contains("ca")) {
            while (n-- > 0)
                out.print("abc");

        } else if (!blocked.contains("ac") && !blocked.contains("cb") && !blocked.contains("ba")) {
            while (n-- > 0)
                out.print("acb");

        } else { // !blocked.contains("aa") && !blocked.contains("bb") && !blocked.contains("cc")

            if (blocked.contains("ab")) {
                for (int i = 0; i < n; i++)
                    out.print('b');
                for (int i = 0; i < n; i++)
                    out.print('c');
                for (int i = 0; i < n; i++)
                    out.print('a');

            } else if (blocked.contains("bc")) {
                for (int i = 0; i < n; i++)
                    out.print('c');
                for (int i = 0; i < n; i++)
                    out.print('a');
                for (int i = 0; i < n; i++)
                    out.print('b');
            } else { // blocked.contains("ca")
                for (int i = 0; i < n; i++)
                    out.print('a');
                for (int i = 0; i < n; i++)
                    out.print('b');
                for (int i = 0; i < n; i++)
                    out.print('c');
            }
        }
    }

    private void solveF() throws IOException {

    }

    private void solveG() throws IOException {
        int n = in.nextInt(), m = in.nextInt();
        int[][] e = new int[n - 1][3];
        for (int i = 0; i < n - 1; i++) {
            e[i] = in.nextIntArray(3);
            e[i][0]--;
            e[i][1]--;
        }
        sort(e, comparingInt(o -> o[2]));
        int[][] q = new int[m][2];
        for (int i = 0; i < m; i++) {
            q[i][0] = in.nextInt();
            q[i][1] = i;
        }
        sort(q, comparingInt(o -> o[0]));
        dsuInit(n);
        ans = 0;
        long[] anss = new long[m];
        for (int i = 0, j = 0; i < m; i++) {
            while (j < n - 1 && e[j][2] <= q[i][0]) {
                dsuUnite(e[j][0], e[j][1]);
                j++;
            }
            anss[q[i][1]] = ans;
        }

        for (int i = 0; i < m; i++)
            out.print(anss[i] + " ");
    }

    long[] sz;
    int[] parent;
    long ans;

    void dsuInit(int n) {
        parent = new int[n];
        sz = new long[n];
        for (int i = 0; i < n; i++) {
            parent[i] = i;
            sz[i] = 1;
        }
    }

    int dsuGet(int v) {
        return v == parent[v] ? v : (parent[v] = dsuGet(parent[v]));
    }

    void dsuUnite(int a, int b) {
        a = dsuGet(a);
        b = dsuGet(b);

        if (a != b) {
            ans -= sz[a] * (sz[a] - 1) / 2;
            ans -= sz[b] * (sz[b] - 1) / 2;
            if (sz[a] < sz[b]) {
                parent[a] = b;
                sz[b] += sz[a];
                ans += sz[b] * (sz[b] - 1) / 2;
            } else {
                parent[b] = a;
                sz[a] += sz[b];
                ans += sz[a] * (sz[a] - 1) / 2;
            }
        }
    }

    void shuffleInt(int[] a) {
        Random random = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            int swap = a[j];
            a[j] = a[i];
            a[i] = swap;
        }
    }

    void shuffleLong(long[] a) {
        Random random = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            long swap = a[j];
            a[j] = a[i];
            a[i] = swap;
        }
    }

    void reverseInt(int[] a) {
        for (int i = 0, j = a.length - 1; i < j; i++, j--) {
            int swap = a[i];
            a[i] = a[j];
            a[j] = swap;
        }
    }

    void reverseLong(long[] a) {
        for (int i = 0, j = a.length - 1; i < j; i++, j--) {
            long swap = a[i];
            a[i] = a[j];
            a[j] = swap;
        }
    }

    int maxInt(int[] a) {
        int max = a[0];
        for (int i = 1; i < a.length; i++)
            if (max < a[i])
                max = a[i];
        return max;
    }

    long maxLong(long[] a) {
        long max = a[0];
        for (int i = 1; i < a.length; i++)
            if (max < a[i])
                max = a[i];
        return max;
    }

    int minInt(int[] a) {
        int min = a[0];
        for (int i = 1; i < a.length; i++)
            if (min > a[i])
                min = a[i];
        return min;
    }

    long minLong(long[] a) {
        long min = a[0];
        for (int i = 1; i < a.length; i++)
            if (min > a[i])
                min = a[i];
        return min;
    }

    long sumInt(int[] a) {
        long s = 0;
        for (int i = 0; i < a.length; i++)
            s += a[i];
        return s;
    }

    long sumLong(long[] a) {
        long s = 0;
        for (int i = 0; i < a.length; i++)
            s += a[i];
        return s;
    }

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long binpowmod(long a, long n) {
        long res = 1;
        a %= mod;
        n %= mod - 1;
        while (n > 0) {
            if (n % 2 == 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
            n /= 2;
        }
        return res;
    }

    class GraphPair implements Comparable<GraphPair> {
        int v;
        long w;

        GraphPair(int v, long w) {
            this.v = v;
            this.w = w;
        }

        public int compareTo(GraphPair o) {
            return w != o.w ? Long.compare(w, o.w) : Integer.compare(v, o.v);
        }
    }

    ArrayList<Integer>[] createGraph(int n) throws IOException {
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++)
            graph[i] = new ArrayList<>();
        return graph;
    }

    ArrayList<GraphPair>[] createWeightedGraph(int n) throws IOException {
        ArrayList<GraphPair>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++)
            graph[i] = new ArrayList<>();
        return graph;
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s), 32768);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();
            return a;
        }

        int[][] nextIntTable(int n, int m) throws IOException {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i][j] = in.nextInt();
            return a;
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextLong();
            return a;
        }

        long[][] nextLongTable(int n, int m) throws IOException {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i][j] = in.nextLong();
            return a;
        }

        ArrayList<Integer>[] nextGraph(int n, int m, boolean directed) throws IOException {
            ArrayList<Integer>[] graph = createGraph(n);
            for (int i = 0; i < m; i++) {
                int v = in.nextInt() - 1, u = in.nextInt() - 1;
                graph[v].add(u);
                if (!directed)
                    graph[u].add(v);
            }
            return graph;
        }

        ArrayList<GraphPair>[] nextWeightedGraph(int n, int m, boolean directed) throws IOException {
            ArrayList<GraphPair>[] graph = createWeightedGraph(n);
            for (int i = 0; i < m; i++) {
                int v = in.nextInt() - 1, u = in.nextInt() - 1;
                long w = in.nextLong();
                graph[v].add(new GraphPair(u, w));
                if (!directed)
                    graph[u].add(new GraphPair(v, w));
            }
            return graph;
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }

    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        for (int t = multitests ? in.nextInt() : 1; t-- > 0; )
            solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}