#include <bits/stdc++.h>
using namespace std;
const int N = 501;
int n, m, v[N], head[N], to[N * 2], len[N * 2], nxt[N * 2], eid;
long long x;
inline void add_edge(int u, int v, int w) {
  to[eid] = v;
  len[eid] = w;
  nxt[eid] = head[u];
  head[u] = eid++;
}
int cnt, L[N], R[N], pos[N];
long long dist[N][N];
void dfs(int u, int lst, int root) {
  if (root == 1) pos[L[u] = ++cnt] = u;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (v == lst) continue;
    dist[root][v] = dist[root][u] + len[i];
    dfs(v, u, root);
  }
  if (root == 1) R[u] = cnt;
}
short dp[N][N][N], tmp[N][N];
int sz[N];
void go(int u, int lst) {
  for (int z = 1; z <= n; z++)
    if (dist[u][z] <= x && z != u) dp[u][0][z] = 0;
  dp[u][1][u] = !v[u];
  sz[u] = 1;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (v == lst) continue;
    go(v, u);
    for (int j = 0; j <= sz[u] + sz[v]; j++)
      for (int z = 1; z <= n; z++) tmp[j][z] = n + 1;
    for (int j = 0; j <= sz[u]; j++)
      for (int k = 0; k <= sz[v] && j + k <= m; k++) {
        for (int z = 1; z <= n; z++)
          tmp[j + k][z] =
              min(tmp[j + k][z], (short)(dp[u][j][z] + dp[v][k][z]));
        short mn = n + 1;
        for (int z = L[v]; z <= R[v]; z++) mn = min(mn, dp[v][k][pos[z]]);
        for (int z = 1; z < L[v]; z++)
          tmp[j + k][pos[z]] =
              min(tmp[j + k][pos[z]], (short)(dp[u][j][pos[z]] + mn));
        for (int z = R[v] + 1; z <= n; z++)
          tmp[j + k][pos[z]] =
              min(tmp[j + k][pos[z]], (short)(dp[u][j][pos[z]] + mn));
      }
    sz[u] += sz[v];
    sz[u] = min(sz[u], m);
    for (int j = 0; j <= sz[u]; j++)
      for (int z = 1; z <= n; z++) dp[u][j][z] = tmp[j][z];
  }
}
int main() {
  scanf("%d%I64d", &n, &x);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]), m += v[i];
  memset(head, -1, sizeof(head));
  eid = 0;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) dist[i][i] = 0, dfs(i, 0, i);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 1; k <= n; k++) dp[i][j][k] = n + 1;
  go(1, 0);
  short ans = n + 1;
  for (int z = 1; z <= n; z++) ans = min(ans, dp[1][m][z]);
  if (ans > n) ans = -1;
  printf("%d\n", ans);
  return 0;
}
