#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T &b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e17 + 7;
const int N = 5005, M = N << 1;
int v[M], nxt[M];
int head[N], sz[N], c[N], d[N], n, b;
int f[2][N][N];
inline void addedge(int p, int x, int y) {
  v[p] = y, nxt[p] = head[x], head[x] = p;
}
inline void dfs(int u) {
  sz[u] = 1;
  for (register int i = (1); i <= (n); ++i) f[0][u][i] = f[1][u][i] = inf;
  f[0][u][1] = c[u];
  f[1][u][1] = c[u] - d[u];
  f[1][u][0] = inf;
  for (int e = head[u]; e; e = nxt[e]) {
    dfs(v[e]);
    for (register int k = (sz[u] + sz[v[e]]); k >= (1); --k) {
      for (register int i = (qmax(0, k - sz[v[e]])); i <= (qmin(sz[u], k));
           ++i) {
        int j = k - i;
        getmin(f[1][u][k], f[1][u][i] + qmin(f[1][v[e]][j], f[0][v[e]][j]));
        getmin(f[0][u][k], f[0][u][i] + f[0][v[e]][j]);
      }
    }
    sz[u] += sz[v[e]];
  }
}
int main() {
  scanf("%d%d", &n, &b);
  scanf("%d%d", c + 1, d + 1);
  for (register int i = (2); i <= (n); ++i) {
    int p;
    scanf("%d%d%d", c + i, d + i, &p);
    addedge(i, p, i);
  }
  dfs(1);
  int ans = 0;
  for (register int i = (1); i <= (n); ++i) {
    if (f[0][1][i] <= b || f[1][1][i] <= b) getmax(ans, i);
  }
  printf("%d\n", ans);
  return 0;
}
