#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<ctime>
#include<queue>
#define rg register
#define lst long long
using namespace std;
#define ll long long
const int N = 100005;
struct edge{int to,next;}a[N];
int head[N],cnt;
int n,Master,ls[N],rs[N],dis[N];
ll m,C[N],L[N],sum[N],sz[N],ans;
ll gi()
{
ll x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
void Link(int u,int v)
{
a[++cnt]=(edge){v,head[u]};
head[u]=cnt;
}
int Merge(int A,int B)
{
if (!A||!B) return A+B;
if (C[A]<C[B]) swap(A,B);
rs[A]=Merge(rs[A],B);
if (dis[ls[A]]<dis[rs[A]]) swap(ls[A],rs[A]);
dis[A]=dis[rs[A]]+1;
return A;
}
int Delete(int A)
{
return Merge(ls[A],rs[A]);
}
int dfs(int u)
{
int A=u,B;
sum[u]=C[u];sz[u]=1;
for (int e=head[u];e;e=a[e].next)
{
int v=a[e].to;
B=dfs(v);
A=Merge(A,B);
sum[u]+=sum[v];sz[u]+=sz[v];
}
while (sum[u]>m)
{
sum[u]-=C[A];sz[u]--;
A=Delete(A);
}
ans=max(ans,L[u]*sz[u]);
return A;
}
int main()
{
n=gi();m=gi();
for (int i=1;i<=n;i++)
{
int u=gi();
if (!u) Master=i;
else Link(u,i);
C[i]=gi();L[i]=gi();
}
dfs(Master);
printf("%lld",ans);
return 0;
}