#include <bits/stdc++.h>
using namespace std;
int root[200005];
long long siz[200005], ans[200005] = {0};
long long sum = 0;
void init(int n) {
  for (int i = 1; i <= n; i++) {
    root[i] = i;
    siz[i] = 1;
  }
}
int fin(int x) { return root[x] == x ? x : (root[x] = fin(root[x])); }
void Union(int a, int b) {
  sum = sum + (long long)siz[fin(a)] * (long long)siz[fin(b)];
  if (siz[fin(a)] < siz[fin(b)]) swap(a, b);
  siz[fin(a)] = siz[fin(a)] + siz[fin(b)];
  root[fin(b)] = fin(a);
}
vector<pair<int, int> > e[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int m, n;
  cin >> n >> m;
  init(n);
  for (int i = 0; i < n - 1; i++) {
    int c, d, v;
    cin >> c >> d >> v;
    e[v].push_back(make_pair(c, d));
  }
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < e[i].size(); j++) {
      int c = e[i][j].first, d = e[i][j].second;
      Union(c, d);
    }
    ans[i] = sum;
  }
  for (int i = 0; i < m; i++) {
    int u;
    cin >> u;
    cout << ans[u] << ' ';
  }
}
