#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
  return x * f;
}
const int N = 5e3 + 5;
inline void Min(int &x, int y) {
  if (y < x) x = y;
}
struct edge {
  int y, next;
} e[N << 1];
int cnt, first[N];
inline void add(int x, int y) {
  e[++cnt] = {y, first[x]};
  first[x] = cnt;
}
int n, v, c[N], d[N], f[N][N][2], ans, siz[N];
void dfs(int x) {
  siz[x] = 1;
  f[x][0][0] = 0;
  f[x][1][0] = c[x];
  f[x][1][1] = c[x] - d[x];
  for (int i = first[x]; i; i = e[i].next) {
    int y = e[i].y;
    dfs(y);
    for (int i = siz[x]; i >= 0; i--)
      for (int j = 0; j <= siz[y]; j++) {
        Min(f[x][i + j][0], f[x][i][0] + f[y][j][0]);
        Min(f[x][i + j][1], f[x][i][1] + f[y][j][0]);
        Min(f[x][i + j][1], f[x][i][1] + f[y][j][1]);
      }
    siz[x] += siz[y];
  }
}
int main() {
  n = read(), v = read();
  for (int i = 1; i <= n; i++) {
    int x;
    c[i] = read(), d[i] = read();
    if (i ^ 1) x = read(), add(x, i);
  }
  memset(f, 0x3f, sizeof(f));
  dfs(1);
  for (int i = n; i >= 1; i--) {
    if (f[1][i][1] <= v) {
      ans = i;
      break;
    }
    if (f[1][i][0] <= v) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
