#include <bits/stdc++.h>
using namespace std;
int64_t binexp(int64_t base, int64_t exponent) {
  int64_t res = 1;
  base = (base + 1000000007) % 1000000007;
  while (exponent) {
    if (exponent & 1) {
      res = (res * base) % 1000000007;
    }
    exponent = exponent >> 1;
    base = (base * base) % 1000000007;
  }
  return res;
}
const int MAX = 300000;
vector<int64_t> par, sz;
int64_t find(int64_t i) {
  vector<int64_t> p;
  while (i != par[i]) {
    p.push_back(i);
    i = par[i];
  }
  for (int j : p) {
    par[j] = i;
  }
  return i;
}
void solve() {
  int n, m;
  cin >> n >> m;
  set<pair<int, pair<int64_t, int64_t>>> ed;
  for (int i = 1; i < n; i++) {
    int u, v, wt;
    cin >> u >> v >> wt;
    ed.insert({wt, {u, v}});
  }
  par.resize(n + 1);
  sz.resize(n + 1);
  for (int64_t i = 0; i <= n; i++) {
    par[i] = i;
    sz[i] = 1LL;
  }
  vector<int64_t> ans(MAX, 0);
  for (auto it : ed) {
    int64_t wt = it.first, u = it.second.first, v = it.second.second;
    int64_t x = find(u), y = find(v);
    int64_t tmp = sz[x] * sz[y];
    ans[wt] += (tmp);
    if (sz[x] < sz[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
    }
  }
  for (int i = 1; i < MAX; i++) {
    ans[i] += ans[i - 1];
  }
  while (m--) {
    int k;
    cin >> k;
    cout << ans[k] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  return 0;
}
