#include <bits/stdc++.h>
using namespace std;
long long z = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % z;
      b--;
    } else {
      a = (a * a) % z;
      b = b >> 1;
    }
  }
  return res;
}
vector<pair<long long, pair<long long, long long> > > v;
long long par[200001], val[200001] = {0}, siz[200001];
long long find_par(long long x) {
  if (par[x] == x) return x;
  return find_par(par[x]);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long x, y, w;
    for (long long i = 1; i < n; i++) {
      cin >> x >> y >> w;
      v.push_back(make_pair(w, make_pair(x, y)));
    }
    sort(v.begin(), v.end());
    for (long long i = 1; i <= n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
    for (long long i = 0; i < n - 1; i++) {
      x = v[i].second.first;
      y = v[i].second.second;
      w = v[i].first;
      x = find_par(x);
      y = find_par(y);
      if (siz[x] < siz[y]) swap(x, y);
      val[w] += siz[x] * siz[y];
      siz[x] += siz[y];
      par[y] = x;
    }
    for (long long i = 1; i <= 200000; i++) {
      val[i] += val[i - 1];
    }
    while (m--) {
      long long q;
      cin >> q;
      cout << val[q] << " ";
    }
    cout << "\n";
  }
}
