#include <bits/stdc++.h>   using namespace std;   int inf = (1 << 30) - 1, n, X, x, y, z, f[510][510], c[510], R, g[510][510],       size[510], h[2][510], H[2][510][510], q[510], L[510];   int Lng[510];   double a[510][510];   vector<int> E[510];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   double Solve(int m, int n) {     bool flag = 1;     for (; flag;) {       flag = 0;       for (int i = 1; i <= n; i++)         if (a[0][i] > 0) {           double Min = inf;           int l;           for (int j = 1; j <= m; j++)             if (a[j][i] < 0) {               double tmp = -a[j][0] / a[j][i];               if (Min > tmp) Min = tmp, l = j;             }           if (Min == inf) continue;           flag = 1;           double tmp = -a[l][i];           a[l][i] = -1;           for (int j = 0; j <= n; j++) a[l][j] /= tmp;           for (int j = 0; j <= m; j++)             if (a[j][i] && j != l) {               for (int k = 0; k <= n; k++)                 if (k != i) a[j][k] += a[j][i] * a[l][k];               a[j][i] *= a[l][i];             }         }     }     return a[0][0];   }   void dfs(int u, int pre) {     int cnt = 0;     for (int i = 0; i < E[u].size(); i++)       if (E[u][i] != pre) {         dfs(E[u][i], u);         ++cnt;         Lng[u] = max(Lng[u], min(Lng[E[u][i]] + f[u][E[u][i]], inf));       }     size[u] = 1;     int A = 0;     for (int j = 0; j <= R; j++) h[A][j] = inf;     for (int Bg = 0; Bg <= cnt; Bg++)       for (int j = 0; j <= R; j++) H[A][Bg][j] = inf;     H[A][0][0] = inf - 1;     h[A][1] = 0;     cnt = 0;     L[0] = -inf;     for (int i = 0; i < E[u].size(); i++)       if (E[u][i] != pre) {         int v = E[u][i];         q[++cnt] = v;         L[cnt] = min(inf, f[u][v] + Lng[v]);         A ^= 1;         for (int j = 0; j <= R; j++) h[A][j] = inf;         for (int Bg = 0; Bg <= cnt; Bg++)           for (int j = 0; j <= R; j++) H[A][Bg][j] = inf;         for (int k = 0; k <= size[u] && k <= R; k++)           for (int j = 0; j <= size[v] && j + k <= R; j++) {             if (j == 0 && max(h[A ^ 1][k], Lng[v] + f[u][v]) <= X)               h[A][j + k] = 0;             if (j && g[v][j] != inf &&                 max(h[A ^ 1][k], min(g[v][j], f[u][v])) <= X)               h[A][j + k] = 0;           }         for (int Bg = 0; Bg < cnt; Bg++)           for (int k = 0; k <= size[u] && k <= R; k++)             if (H[A ^ 1][Bg][k] != inf) {               for (int j = 1; j + k <= R && j <= size[v]; j++)                 if (g[v][j] <= X)                   H[A][Bg][j + k] = min(H[A][Bg][j + k],                                         min(H[A ^ 1][Bg][k], g[v][j] + f[u][v]));               if (L[cnt] > L[Bg])                 H[A][cnt][k] = min(H[A][cnt][k], H[A ^ 1][Bg][k]);               else                 H[A][Bg][k] = min(H[A][Bg][k], H[A ^ 1][Bg][k]);             }         size[u] += size[v];       }     for (int j = 0; j <= R; j++) g[u][j] = h[A][j];     for (int Bg = 0; Bg <= cnt; Bg++)       for (int j = 0; j <= R; j++)         if (H[A][Bg][j] + L[Bg] <= X) g[u][j] = min(g[u][j], H[A][Bg][j]);   }   bool check() {     for (int i = 1; i <= n; i++)       for (int j = 0; j <= n; j++) g[i][j] = inf;     dfs(1, 0);     return (g[1][R] <= X);   }   int main() {     read(n);     read(X);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) f[i][j] = inf;       f[i][i] = 0;       read(c[i]);       R += c[i];     }     for (int i = 1; i < n; i++) {       read(x);       read(y);       read(z);       f[x][y] = f[y][x] = z;       E[x].push_back(y);       E[y].push_back(x);     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         if (i ^ k)           for (int j = 1; j <= n; j++)             if ((i ^ j) && (k ^ j)) f[i][j] = min(f[i][k] + f[k][j], f[i][j]);     if (!check()) {       printf( -1 n );       return 0;     }     a[0][n + 1] = -R;     for (int i = 1; i <= n; i++) {       a[0][i] = 1;       a[i][n + 1] = 1;       a[i][0] = c[i] ^ 1;       for (int j = 1; j <= n; j++) a[i][j] = -(f[i][j] <= X);     }     printf( %.0lf n , Solve(n, n + 1));     return 0;   }