/*
SEFI
*/
#include <set>
#include <vector>
#include <cstdio>
using namespace std;
const int N = 100009;
vector <int> g [ N ];
multiset <int> q[ N ];
int summa[N];
int udov [ N ];
int cost [ N ];
long long res = 0;
int m;
void add (int &v , int &u){
multiset <int> &a = q[v];
multiset <int> &b = q[u];
if (a.size() < b.size())
a.swap (b) , swap (summa[v] , summa[u]);
for (multiset <int> ::iterator it = b.begin() ; it != b.end() ; ++it){
if (summa[v] + *it <= m)
a.insert (*it) , summa[v] += *it;
else {
if (!a.empty()&& *it < *(--a.end()))
summa[v] -=*(--a.end()) ,
summa[v] += *it ,
a.erase ((--a.end())) , a.insert (*it);
}
}
b.clear();
}
int n ;
void dfs (int v , int p = 0){
if (cost[v] + summa[v] <= m)
q[v].insert (cost[v]) , summa[v] += cost[v];
for (int i = 0 ; i < (int)g[v].size() ; ++i){
int to = g[v][i];
dfs (to , v);
add (v , to);
}
res = max (res , (int)q[v].size() * 1LL * udov[v]);
}
#define pb push_back
int main(){
scanf ("%d%d" , &n , &m);
for (int i = 1 ; i <= n ; ++i){
int boss; scanf ("%d%d%d" , &boss , &cost[i] , &udov[i]);
g[boss].pb(i);
}
dfs (1);
printf ("%lld\n" , res);
return 0;
}
LyoKICBTRUZJCiovCgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGlvPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCgpjb25zdCBpbnQgTiA9IDEwMDAwOTsKdmVjdG9yIDxpbnQ+IGcgWyBOIF07Cm11bHRpc2V0IDxpbnQ+IHFbIE4gXTsKaW50IHN1bW1hW05dOwoKaW50IHVkb3YgWyBOIF07CmludCBjb3N0IFsgTiBdOwoKbG9uZyBsb25nIHJlcyA9IDA7CmludCBtOwp2b2lkIGFkZCAoaW50ICZ2ICwgaW50ICZ1KXsKICAgICAgICAgICAgbXVsdGlzZXQgPGludD4gJmEgPSBxW3ZdOwogICAgICAgICAgICBtdWx0aXNldCA8aW50PiAmYiA9IHFbdV07CiAgICAgICAgICAgIGlmIChhLnNpemUoKSA8IGIuc2l6ZSgpKQogICAgICAgICAgICAgIGEuc3dhcCAoYikgLCBzd2FwIChzdW1tYVt2XSAsIHN1bW1hW3VdKTsKCiAgICAgICAgICAgIGZvciAobXVsdGlzZXQgPGludD4gOjppdGVyYXRvciBpdCA9IGIuYmVnaW4oKSA7IGl0ICE9IGIuZW5kKCkgOyArK2l0KXsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdW1tYVt2XSArICppdCA8PSBtKQogICAgICAgICAgICAgICAgICAgICAgYS5pbnNlcnQgKCppdCkgLCBzdW1tYVt2XSArPSAqaXQ7CiAgICAgICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWEuZW1wdHkoKSYmICppdCA8ICooLS1hLmVuZCgpKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdW1tYVt2XSAtPSooLS1hLmVuZCgpKSAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3VtbWFbdl0gKz0gKml0ICwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhLmVyYXNlICgoLS1hLmVuZCgpKSkgLCBhLmluc2VydCAoKml0KTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBiLmNsZWFyKCk7Cn0KCmludCBuIDsKCnZvaWQgZGZzIChpbnQgdiAsIGludCBwID0gMCl7CiAgICAgIGlmIChjb3N0W3ZdICsgc3VtbWFbdl0gPD0gbSkKICAgICAgICAgICAgcVt2XS5pbnNlcnQgKGNvc3Rbdl0pICwgc3VtbWFbdl0gKz0gY29zdFt2XTsKICAgICAgZm9yIChpbnQgaSA9IDAgOyBpIDwgKGludClnW3ZdLnNpemUoKSA7ICsraSl7CiAgICAgICAgICAgICAgICAgIGludCB0byA9IGdbdl1baV07CiAgICAgICAgICAgICAgICAgIGRmcyAodG8gLCB2KTsKICAgICAgICAgICAgICAgICAgYWRkICh2ICwgdG8pOwogICAgICB9CiAgICAgIHJlcyA9IG1heCAocmVzICwgKGludClxW3ZdLnNpemUoKSAqIDFMTCAqIHVkb3Zbdl0pOwp9CgojZGVmaW5lIHBiIHB1c2hfYmFjawoKaW50IG1haW4oKXsKCiAgc2NhbmYgKCIlZCVkIiAsICZuICwgJm0pOwogIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgKytpKXsKICAgICAgICAgICAgICBpbnQgYm9zczsgc2NhbmYgKCIlZCVkJWQiICwgJmJvc3MgLCAmY29zdFtpXSAsICZ1ZG92W2ldKTsKICAgICAgICAgICAgICBnW2Jvc3NdLnBiKGkpOwogIH0KICBkZnMgKDEpOwogIHByaW50ZiAoIiVsbGRcbiIgLCByZXMpOwoKICByZXR1cm4gMDsKfQ==