#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y, t, tot;
static const int N = 501;
int size[N], s;
short f[N][N][N], be[N][N];
long long d[N][N];
int fi[N], ne[N * 2], la[N * 2], a[N * 2];
short w[N], tem[N];
void add(int x, int y) {
  k++;
  a[k] = y;
  if (fi[x] == 0)
    fi[x] = k;
  else
    ne[la[x]] = k;
  la[x] = k;
}
void dp(int x, int fa) {
  int i, cor, j, k;
  size[x] = 1;
  for (i = fi[x]; i; i = ne[i])
    if (a[i] != fa) {
      dp(a[i], x);
      size[x] += size[a[i]];
    }
  for (i = 1; i <= size[x]; i++) be[x][i] = 520;
  for (cor = 1; cor <= n; cor++) {
    if (d[x][cor] > m) continue;
    for (i = 0; i <= size[x]; i++) tem[i] = 520;
    tem[0] = tem[1] = 0;
    int sx = 1;
    for (i = fi[x]; i; i = ne[i]) {
      if (a[i] == fa) continue;
      for (j = min(tot, sx + size[a[i]]); j >= 0; j--) {
        short mn = 520;
        for (k = max(j - sx, 0); k <= min(j, size[a[i]]); k++) {
          mn = min(mn, min((short)(tem[j - k] + be[a[i]][k]),
                           (short)(tem[j - k] + f[a[i]][cor][k])));
        }
        tem[j] = mn;
      }
      sx += size[a[i]];
    }
    for (i = 0; i <= size[x]; i++) f[x][cor][i] = tem[i];
    for (i = 0; i < size[x]; i++)
      be[x][i + 1] = min(be[x][i + 1], short(f[x][cor][i] + w[cor]));
  }
}
int main() {
  memset(f, 5, sizeof f);
  memset(be, 5, sizeof be);
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &w[i]), tot += w[i], w[i] = 1 - w[i];
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) d[i][j] = d[j][i] = 1ll << 60;
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &t);
    d[x][y] = d[y][x] = t;
    add(x, y);
    add(y, x);
  }
  for (k = 1; k <= n; k++)
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++)
        if (i != j && i != k && j != k)
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  dp(1, -1);
  short ans = 520;
  for (i = 1; i <= tot; i++) ans = min(ans, be[1][i]);
  if (ans == 520) ans = -1;
  printf("%d\n", ans);
  return 0;
}
