#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010][2];
vector<int> g[5010];
int cs[5010][2];
int n, b;
int siz[5010];
void Min(int &x, int y) {
  x = min(x, y);
  if (x > b) x = b + 1;
}
int tmp[5010][2];
void clr(int u, int x) {
  for (int i = 0; i <= x; ++i)
    for (int j = 0; j < 2; ++j) tmp[i][j] = 0x3f3f3f3f;
}
void cpy(int u, int x) {
  for (int i = 0; i <= x; ++i)
    for (int j = 0; j < 2; ++j) dp[u][i][j] = tmp[i][j];
}
void dfs(int u) {
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j < 2; ++j) dp[u][i][j] = 0x3f3f3f3f;
  dp[u][0][0] = 0;
  dp[u][1][0] = cs[u][0];
  dp[u][1][1] = cs[u][1];
  siz[u] = 1;
  for (int i = 0; i < (int)g[u].size(); ++i) {
    int v = g[u][i];
    dfs(v);
    clr(u, siz[u] + siz[v]);
    for (int j = 0; j <= siz[u]; ++j)
      for (int k = 0; k <= siz[v]; ++k) {
        Min(tmp[j + k][1], dp[u][j][1] + min(dp[v][k][1], dp[v][k][0]));
        Min(tmp[j + k][0], dp[u][j][0] + dp[v][k][0]);
      }
    cpy(u, siz[u] + siz[v]);
    siz[u] += siz[v];
  }
}
int main() {
  scanf("%d%d", &n, &b);
  scanf("%d%d", &cs[1][0], &cs[1][1]);
  cs[1][1] = cs[1][0] - cs[1][1];
  for (int i = 2; i <= n; ++i) {
    int fa;
    scanf("%d%d%d", &cs[i][0], &cs[i][1], &fa);
    cs[i][1] = cs[i][0] - cs[i][1];
    g[fa].push_back(i);
  }
  dfs(1);
  for (int i = n; i >= 0; --i)
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      printf("%d\n", i);
      return 0;
    }
  return 0;
}
