#include <bits/stdc++.h>
using namespace std;
vector<int> f;
vector<int> cnt;
vector<tuple<int, int, int> > tr;
vector<tuple<int, int> > cw;
vector<long long> answ;
int n, m;
int getF(int u) { return f[u] == u ? u : f[u] = getF(f[u]); }
void read_data() {
  cin >> n >> m;
  cnt.resize(n + 1);
  f.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    cnt[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    tr.emplace_back(w, u, v);
  }
  cw.reserve(m);
  for (int i = 0; i < m; i++) {
    int w;
    scanf("%d", &w);
    cw.emplace_back(w, i);
  }
  sort(tr.begin(), tr.end());
  sort(cw.begin(), cw.end());
}
void deal() {
  int i = 0;
  long long ans = 0;
  answ.resize(m);
  for (int k = 0; k < m; k++) {
    while (i < n - 1 && get<0>(tr[i]) <= get<0>(cw[k])) {
      int fu = getF(get<1>(tr[i]));
      int fv = getF(get<2>(tr[i]));
      int cfu = cnt[fu];
      int cfv = cnt[fv];
      ans += 1LL * (cfu + cfv) * (cfu + cfv - 1) / 2 -
             1LL * cfu * (cfu - 1) / 2 - 1LL * cfv * (cfv - 1) / 2;
      f[fu] = fv;
      cnt[fv] += cnt[fu];
      i++;
    }
    answ[get<1>(cw[k])] = ans;
  }
  for (int i = 0; i < m; i++) printf("%I64d ", answ[i]);
  cout << endl;
}
int main() {
  read_data();
  deal();
  return 0;
}
