#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 502;
int d[MAX_N][MAX_N];
int g[MAX_N << 1], nxt[MAX_N << 1], c[MAX_N], nm;
int n, D, m;
int a[MAX_N];
short f[MAX_N][MAX_N][MAX_N];
int F[MAX_N][MAX_N], h[MAX_N], q[MAX_N];
int s[MAX_N];
inline void relax(int &x, int y) {
  if (x > y) x = y;
}
void addedge(int x, int y) {
  g[nm] = y;
  nxt[nm] = c[x];
  c[x] = nm;
  nm++;
}
void dfs(int i, int p) {
  for (int e = (1); e <= (m); ++e) F[i][e] = 10007;
  for (int x = (1); x <= (n); ++x)
    for (int e = (1); e <= (m); ++e) f[i][x][e] = 10007;
  for (int k = c[i]; ~k; k = nxt[k]) {
    int j = g[k];
    if (j != p) dfs(j, i);
  }
  for (int x = (1); x <= (n); ++x) {
    s[i] = 1;
    q[1] = a[x];
    for (int e = (2); e <= (m); ++e) q[e] = 10007;
    for (int k = c[i]; ~k; k = nxt[k]) {
      int j = g[k];
      if (j == p) continue;
      for (int e = (1); e <= (s[i]); ++e) h[e] = q[e], q[e] = 10007;
      for (int e1 = (1); e1 <= (s[i]); ++e1) {
        int mx = s[j];
        relax(mx, m - e1 + 1);
        for (int e2 = (1); e2 <= (mx); ++e2) {
          relax(q[e1 + e2], h[e1] + F[j][e2]);
          if (d[j][x] <= D) relax(q[e1 + e2 - 1], h[e1] + f[j][x][e2] - a[x]);
        }
      }
      s[i] += s[j];
    }
    if (d[i][x] <= D)
      for (int e = (1); e <= (m); ++e) {
        relax(F[i][e], q[e]);
        f[i][x][e] = q[e];
      }
  }
}
int main() {
  memset(c, -1, sizeof c);
  scanf("%d%d", &n, &D);
  for (int i = (1); i <= (n); ++i) {
    scanf("%d", &a[i]);
    m += a[i];
    a[i] ^= 1;
  }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (n); ++j) d[i][j] = i == j ? 0 : 1000000007;
  for (int i = (1); i <= (n - 1); ++i) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    addedge(x, y);
    addedge(y, x);
    d[x][y] = d[y][x] = w;
  }
  for (int k = (1); k <= (n); ++k)
    for (int i = (1); i <= (n); ++i)
      for (int j = (1); j <= (n); ++j) {
        if (k == i || i == j || k == j) continue;
        relax(d[i][j], d[i][k] + d[k][j]);
      }
  dfs(1, -1);
  if (F[1][m] == 10007)
    puts("-1");
  else
    printf("%d\n", F[1][m]);
}
