#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
long long kn[1100][11000];
long long weight[1100];
long long value[1100];
int n, b;
int p[1100];
vector<int> adj[1100];
void dfs(int v) {
for (int i = 0; i <= b; i++) {
kn[v][i] = kn[p[v]][i];
}
for (int i = 0; i < adj[v].size(); i++) {
dfs(adj[v][i]);
}
for (int i = 0; i+weight[v] <= b; i++) {
if (kn[v][i] != -1) {
kn[p[v]][i + weight[v]] = max(kn[p[v]][i], kn[v][i] + value[v]);
}
}
}
int main() {
scanf("%d %d", &n, &b);
memset(kn[0], -1, sizeof(kn[0]));
kn[0][0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d %lld %lld", &p[i], &weight[i], &value[i]);
adj[p[i]].push_back(i);
}
for (int i = 1; i <= n; i++)
if (p[i] == 0)
dfs(i);
long long ans = 0;
for (int i = 0; i <= b; i++) ans = max(ans, kn[0][i]);
printf("%lld\n", ans);
}
I2luY2x1ZGUgPHZlY3Rvcj4gCiNpbmNsdWRlIDxjc3RkaW8+IAojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7IAoKbG9uZyBsb25nIGtuWzExMDBdWzExMDAwXTsKbG9uZyBsb25nIHdlaWdodFsxMTAwXTsKbG9uZyBsb25nIHZhbHVlWzExMDBdOwppbnQgbiwgYjsKaW50IHBbMTEwMF07CnZlY3RvcjxpbnQ+IGFkalsxMTAwXTsKCnZvaWQgZGZzKGludCB2KSB7Cglmb3IgKGludCBpID0gMDsgaSA8PSBiOyBpKyspIHsKCQlrblt2XVtpXSA9IGtuW3Bbdl1dW2ldOwoJfQoKCWZvciAoaW50IGkgPSAwOyBpIDwgYWRqW3ZdLnNpemUoKTsgaSsrKSB7CgkJZGZzKGFkalt2XVtpXSk7Cgl9CgoJZm9yIChpbnQgaSA9IDA7IGkrd2VpZ2h0W3ZdIDw9IGI7IGkrKykgewoJCWlmIChrblt2XVtpXSAhPSAtMSkgewoJCQlrbltwW3ZdXVtpICsg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