#include <bits/stdc++.h>
using namespace std;
const int N = 5003, INF = 1e9 + 7;
int n, b, c[N], d[N], siz[N];
vector<int> ed[N], sons[N];
int dp1[N][N], dp2[N][N];
int stk[N], stksiz;
void dfs(int u) {
  siz[u] = 1;
  dp2[u][1] = c[u] - d[u];
  for (int to : ed[u]) {
    dfs(to);
    siz[u] += siz[to];
    for (int i = siz[u]; i >= 2; i--) {
      int low = max(i + siz[to] - siz[u], 1), up = min(i, siz[to]);
      for (int j = low; j <= up; j++) {
        dp2[u][i] = min(dp2[u][i], dp2[u][i - j] + dp1[to][j]);
      }
    }
  }
  for (int i = 1; i <= siz[u]; i++) {
    dp1[u][i] = min(dp1[u][i], dp2[u][i]);
  }
}
void dfs2(int u) {
  sons[u].push_back(c[u]);
  for (int to : ed[u]) {
    dfs2(to);
    sons[u].insert(sons[u].end(), sons[to].begin(), sons[to].end());
    sons[to].clear();
  }
  sort(sons[u].begin(), sons[u].end());
  for (int i = 0; i < sons[u].size(); i++) {
    dp1[u][i + 1] = dp1[u][i] + sons[u][i];
    if (dp1[u][i + 1] > b) {
      sons[u].erase(sons[u].begin() + i, sons[u].end());
      break;
    }
  }
}
int main() {
  scanf("%d%d", &n, &b);
  scanf("%d%d", c + 1, d + 1);
  for (int i = 2; i <= n; i++) {
    int v;
    scanf("%d%d%d", c + i, d + i, &v);
    ed[v].push_back(i);
  }
  for (int i = 0; i <= n; i++) {
    fill(dp1[i] + 1, dp1[i] + n + 1, INF);
    fill(dp2[i], dp2[i] + n + 1, INF);
  }
  dp2[0][0] = 0;
  dfs2(1);
  dfs(1);
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp1[1][i] <= b) ans = max(ans, i);
    if (dp2[1][i] <= b) ans = max(ans, i);
  }
  printf("%d\n", ans);
}
