#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int from, to, next;
} edge[5010 << 1];
int tot, head[5010];
inline void addedge(int u, int v) {
  edge[++tot] = (Edge){u, v, head[u]};
  head[u] = tot;
  edge[++tot] = (Edge){v, u, head[v]};
  head[v] = tot;
}
int n, b, c[5010], d[5010], seq[5010], cnt, fa[5010], size[5010];
int f[5010][5010], g[5010][5010], s[5010];
inline void dfs(int now, int fa) {
  seq[++cnt] = c[now];
  for (int i = head[now]; i; i = edge[i].next) {
    Edge e = edge[i];
    if (e.to != fa) {
      dfs(e.to, now);
    }
  }
}
inline void getg() {
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    dfs(i, fa[i]);
    size[i] = cnt;
    sort(seq + 1, seq + cnt + 1);
    g[i][0] = 0;
    for (int j = 1; j <= cnt; j++) {
      g[i][j] = min(g[i][j], g[i][j - 1] + seq[j]);
    }
  }
}
inline void getf(int now, int fa) {
  f[now][1] = d[now];
  for (int i = head[now]; i; i = edge[i].next) {
    Edge e = edge[i];
    if (e.to != fa) {
      getf(e.to, now);
    }
  }
  int cnt = 1;
  memset(s, 0x3f, sizeof(s));
  for (int i = head[now]; i; i = edge[i].next) {
    Edge e = edge[i];
    if (e.to == fa) continue;
    for (int j = 0; j <= size[e.to]; j++) {
      for (int k = 0; k <= cnt; k++) {
        s[j + k] = min(s[j + k], min(f[e.to][j], g[e.to][j]) + f[now][k]);
      }
    }
    cnt += size[e.to];
    for (int j = 0; j <= cnt; j++) {
      f[now][j] = min(f[now][j], s[j]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &b);
  memset(f, 0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &c[i], &d[i]);
    d[i] = c[i] - d[i];
    if (i > 1) {
      int x;
      scanf("%d", &x);
      addedge(i, x);
      fa[i] = x;
    }
  }
  getg();
  getf(1, 0);
  int ans = 0;
  for (int i = n; i > 0; i--) {
    if (f[1][i] <= b || g[1][i] <= b) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
