#include <bits/stdc++.h>
#pragma GCC target("sse2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int maxn = 1000500;
inline int g() {
  int x;
  cin >> x;
  return x;
}
inline long long gl() {
  long long x;
  cin >> x;
  return x;
}
inline char gc() {
  char x;
  cin >> x;
  return x;
}
inline string gs() {
  string s;
  cin >> s;
  return s;
}
template <typename T>
inline vector<T> gv(int len) {
  vector<T> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<int> gv(int len) {
  vector<int> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<pair<int, int>> gv_andPairCnt(int len) {
  vector<pair<int, int>> a(len);
  int i = 1;
  for (auto &it : a) {
    it.second = i;
    i++;
    cin >> it.first;
  }
  return a;
}
double power_log(double power, double val) { return log(val) / log(power); }
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it : v) os << it << ", ";
  os << "\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &v) {
  os << "deque:{";
  for (auto it : v) os << it << " ";
  os << "}\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "set:{";
  for (auto it : v) os << it << " ";
  os << "}";
  return os;
}
template <typename T, typename T2>
ostream &operator<<(ostream &os, const map<T, T2> &v) {
  os << "map:{\n";
  for (auto it : v) os << "    {" << it.first << " <> " << it.second << "}\n";
  os << "}\n";
  return os;
}
template <typename T, typename T2>
ostream &operator<<(ostream &os, const pair<T, T2> &v) {
  os << "{" << v.first << ", " << v.second << "}";
  return os;
}
template <typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
  vector<pair<T, H>> a(len);
  for (auto &it : a) {
    cin >> it.first >> it.second;
  }
  return a;
}
template <typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
  set<T> s;
  for (auto &it : vec) s.insert(it);
  return s;
}
const long long md = 1e9 + 7;
template <typename T>
class fenwick {
 public:
  vector<T> fenw;
  int n;
  fenwick(int _n) : n(_n) { fenw.resize(n); }
  void modify(int x, T v) {
    while (x < n) {
      fenw[x] += v;
      x |= (x + 1);
    }
  }
  T get(int x) {
    T v{};
    while (x >= 0) {
      v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};
vector<int> arr[maxn];
int n, mxm, price[maxn], sale[maxn];
pair<int, int> path[maxn];
using vii2 = pair<pair<int, bool>, int>;
vector<vii2> dp[maxn], tmp;
const int mx = 5001;
int tmp1[mx][2];
void umin(int &x, int val) {
  if (x == -1) {
    x = val;
  } else
    x = min(x, val);
}
void merge(vector<vii2> &l, vector<vii2> &r, int v, bool safe = false) {
  memset(tmp1, -1, sizeof(tmp1));
  for (auto &it : l) {
    for (auto &it2 : r) {
      if (it.first.second && it2.first.second) {
        if (it.second + it2.second - path[v].second > mxm) {
          continue;
        }
        umin(tmp1[it.first.first + it2.first.first - path[v].first][true],
             it.second + it2.second - path[v].second);
      } else {
        if (safe && it.first.second && !it2.first.second) {
          continue;
        }
        if (it.second + it2.second > mxm) {
          continue;
        }
        umin(tmp1[it.first.first + it2.first.first]
                 [it.first.second || it2.first.second],
             it.second + it2.second);
      }
    }
  }
  for (auto &it : l) {
    umin(tmp1[it.first.first][it.first.second], it.second);
  }
  for (auto &it : r) {
    umin(tmp1[it.first.first][it.first.second], it.second);
  }
  tmp.clear();
  for (int i = 0; i < (mx); ++i)
    for (int j = 0; j < (2); ++j) {
      if (tmp1[i][j] != -1) {
        tmp.push_back({{i, j}, tmp1[i][j]});
      }
    }
}
void rec1(int v, int cnt = 0, int fg = 0) {
  cnt += 1, fg += sale[v];
  if (fg > mxm) {
    cnt += n;
    fg = 0;
  }
  path[v] = make_pair(cnt, fg);
  for (auto &it : arr[v]) {
    rec1(it, cnt, fg);
  }
}
void calc(int v) {
  for (auto &it : arr[v]) {
    calc(it);
  }
  int pos = -1, sz = 0;
  for (auto &it : arr[v]) {
    if (dp[it].size() > sz) {
      pos = it;
      sz = dp[it].size();
    }
  }
  if (pos == -1) {
    dp[v].push_back({{1, 0}, price[v]});
    if (path[v].first <= n)
      dp[v].push_back({{path[v].first, 1}, path[v].second});
  } else {
    swap(dp[v], dp[pos]);
    for (auto &it : arr[v]) {
      if (pos == it) {
        continue;
      }
      merge(dp[v], dp[it], v);
      swap(dp[v], tmp);
    }
    dp[pos].push_back({{1, 0}, price[v]});
    if (path[v].first <= n)
      dp[pos].push_back({{path[v].first, 1}, path[v].second});
    merge(dp[v], dp[pos], v, true);
    swap(dp[v], tmp);
    for (auto &it : arr[v]) {
      dp[it].clear();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  n = g(), mxm = g();
  {
    price[1] = g(), sale[1] = g();
    sale[1] = price[1] - sale[1];
  }
  for (int i = 2; i <= n; i++) {
    price[i] = g(), sale[i] = g();
    sale[i] = price[i] - sale[i];
    int x = g();
    arr[x].push_back(i);
  }
  rec1(1);
  calc(1);
  int ans = 0;
  for (auto &it : dp[1]) {
    if (it.second <= mxm) ans = max(ans, it.first.first);
  }
  cout << ans;
}
