#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long p[N], sz[N], res[N];
vector<int> a[N], b[N];
int f(int r) { return p[r] != r ? p[r] = f(p[r]) : r; }
long long g(int u, int v) {
  int x = f(u), y = f(v);
  long long res = sz[x] * sz[y];
  p[x] = y;
  sz[y] += sz[x];
  return res;
}
int main() {
  int n, m, x, y, z;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;
  for (int i = 1; i < n; i++) {
    cin >> x >> y >> z;
    a[z].push_back(x);
    b[z].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    res[i] = res[i - 1];
    for (int j = 0; j < a[i].size(); j++) res[i] += g(a[i][j], b[i][j]);
  }
  while (m--) {
    cin >> x;
    cout << res[x] << " ";
  }
}
