#include <bits/stdc++.h>
using namespace std;
int n, K, R, red[505], sz[505];
int tote, TO[1010], NEXT[1010], W[1010], FIR[505];
bool g[505][505];
short dp[505][505][505], tp[505][505], tmp[505][505];
void addedge(int u, int v, int w) {
  TO[++tote] = v;
  W[tote] = w;
  NEXT[tote] = FIR[u];
  FIR[u] = tote;
}
void dfs(int rt, int u, int fa, int dis) {
  g[rt][u] = 1;
  for (int p = FIR[u]; p; p = NEXT[p]) {
    int v = TO[p], w = W[p];
    if (v == fa) continue;
    if (dis + w <= K) dfs(rt, v, u, dis + w);
  }
}
void solve(int u, int fa) {
  sz[u] = 1;
  for (int h = 1; h <= n; h++)
    if (g[u][h]) dp[u][0][h] = 0;
  for (int p = FIR[u]; p; p = NEXT[p]) {
    int v = TO[p];
    if (v == fa) continue;
    solve(v, u);
    memset(tmp, 0x3f3f3f3f, sizeof(tmp));
    for (int h = 0; h <= n; h++)
      if (g[u][h])
        for (int i = 0; i <= sz[u]; i++)
          for (int j = 0; j <= sz[v]; j++) {
            tmp[i + j + 1][h] = (tmp[i + j + 1][h] < dp[u][i][h] + tp[v][j]
                                     ? tmp[i + j + 1][h]
                                     : dp[u][i][h] + tp[v][j]);
            tmp[i + j][h] = (tmp[i + j][h] < dp[u][i][h] + dp[v][j][h]
                                 ? tmp[i + j][h]
                                 : dp[u][i][h] + dp[v][j][h]);
          }
    memcpy(dp[u], tmp, sizeof(tmp));
    sz[u] += sz[v];
  }
  for (int i = 0; i <= sz[u]; i++)
    for (int h = 0; h <= n; h++)
      if (g[u][h])
        tp[u][i] = (tp[u][i] < dp[u][i][h] + !red[h] ? tp[u][i]
                                                     : dp[u][i][h] + !red[h]);
}
int main() {
  int i, u, v, w;
  scanf("%d%d", &n, &K);
  if (!K) {
    puts("-1");
    return 0;
  }
  for (i = 1; i <= n; i++) scanf("%d", &red[i]), R += red[i];
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (i = 1; i <= n; i++) dfs(i, i, 0, 0);
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  memset(tp, 0x3f3f3f3f, sizeof(tp));
  solve(1, 0);
  int Ans = 0x3f3f3f3f;
  Ans = tp[1][R - 1];
  printf("%d\n", Ans <= n ? Ans : -1);
}
