#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
long double eps = 1e-9;
long long pp = 1000000007;
long long mo(long long a, long long pp) {
  if (a >= 0 && a < pp) return a;
  a %= pp;
  if (a < 0) a += pp;
  return a;
}
long long powmod(long long a, long long b, long long pp) {
  long long ans = 1;
  for (; b; b >>= 1, a = mo(a * a, pp))
    if (b & 1) ans = mo(ans * a, pp);
  return ans;
}
long long read() {
  long long ans = 0;
  char last = ' ', ch = getchar();
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
int head[5100], v[5100], Next[5100], n, lim, siz[5100], num, dp[2][5100][5100],
    ff[2][5100], c[5100], d[5100], fa[5100];
void add(int x, int y) {
  v[++num] = y;
  Next[num] = head[x];
  head[x] = num;
}
void dfs(int u) {
  siz[u] = 1;
  dp[1][u][1] = c[u] - d[u];
  dp[0][u][1] = c[u];
  dp[0][u][0] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    dfs(v[i]);
    for (int j = 0; j <= siz[u] + siz[v[i]]; j++) ff[0][j] = ff[1][j] = lim + 1;
    for (int j = 0; j <= siz[u]; j++)
      for (int j2 = 0; j2 <= siz[v[i]]; j2++) {
        if (j > 0)
          ff[1][j + j2] = min(ff[1][j + j2], dp[1][u][j] + dp[1][v[i]][j2]);
        if (j > 0)
          ff[1][j + j2] = min(ff[1][j + j2], dp[1][u][j] + dp[0][v[i]][j2]);
        ff[0][j + j2] = min(ff[0][j + j2], dp[0][u][j] + dp[0][v[i]][j2]);
      }
    for (int j = 0; j <= siz[u] + siz[v[i]]; j++) {
      dp[0][u][j] = min(ff[0][j], dp[0][u][j]);
      dp[1][u][j] = min(ff[1][j], dp[1][u][j]);
    }
    siz[u] += siz[v[i]];
  }
}
int main() {
  n = read();
  lim = read();
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[0][i][j] = dp[1][i][j] = lim + 1;
  c[1] = read();
  d[1] = read();
  for (int i = 2; i <= n; i++) c[i] = read(), d[i] = read(), fa[i] = read();
  for (int i = 2; i <= n; i++) add(fa[i], i);
  dfs(1);
  int t = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[0][1][i] <= lim) t = max(t, i);
    if (dp[1][1][i] <= lim) t = max(t, i);
  }
  cout << t << endl;
  return 0;
}
