#include <bits/stdc++.h>
using namespace std;
int n, K, c[510], sum = 0, head[510], o = 0, dfn[510], x = 0, sz[510];
long long dis[510][510];
short f[503][503][503], tmp[503][503];
struct edge {
  int to, link, w;
} e[1010];
void add_edge(int u, int v, int w) {
  e[++o].to = v, e[o].link = head[u], head[u] = o, e[o].w = w;
  e[++o].to = u, e[o].link = head[v], head[v] = o, e[o].w = w;
}
void get(int u, int pre, long long *dis) {
  for (int i = head[u]; i; i = e[i].link) {
    if (e[i].to == pre) continue;
    dis[e[i].to] = dis[u] + e[i].w;
    get(e[i].to, u, dis);
  }
}
bool in(int u, int v) {
  return dfn[u] <= dfn[v] && dfn[v] <= dfn[u] + sz[u] - 1;
}
void dfs(int u, int pre) {
  sz[u] = 1, dfn[u] = ++x;
  for (int i = 1; i <= n; i++)
    if (i != u && dis[u][i] <= K) f[u][0][i] = 0;
  f[u][1][u] = c[u] ^ 1;
  for (int i = head[u]; i; i = e[i].link) {
    int v = e[i].to;
    if (v == pre) continue;
    dfs(v, u);
    int L1 = min(sum, sz[u]), L2 = min(sum, sz[v]);
    sz[u] += sz[v];
    for (int j = 0; j <= L1 + L2; j++)
      for (int l = 1; l <= n; l++) tmp[j][l] = 32767;
    for (int j = 0; j <= L1; j++)
      for (int k = 0; k <= L2; k++) {
        for (int l = 1; l <= n; l++)
          tmp[j + k][l] = min((int)tmp[j + k][l], f[u][j][l] + f[v][k][l]);
        short mn = 32767;
        for (int l = 1; l <= n; l++)
          if (in(v, l)) mn = min(mn, f[v][k][l]);
        for (int l = 1; l <= n; l++)
          if (!in(v, l))
            tmp[j + k][l] = min((int)tmp[j + k][l], f[u][j][l] + mn);
      }
    for (int j = 0; j <= L1 + L2; j++)
      for (int l = 1; l <= n; l++) f[u][j][l] = tmp[j][l];
  }
}
int main() {
  memset(f, 0X3f, sizeof(f));
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]), sum += c[i];
  for (int i = 1, u, v, w; i < n; i++)
    scanf("%d%d%d", &u, &v, &w), add_edge(u, v, w);
  for (int i = 1; i <= n; i++) get(i, 0, dis[i]);
  dfs(1, 0);
  int ans = INT_MAX;
  for (int i = 0; i <= sum; i++)
    for (int j = 1; j <= n; j++) ans = min(ans, (int)f[1][i][j]);
  printf("%d\n", ans > n ? -1 : ans);
}
