#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define rep(s,t) for(int i=s;i<=t;i++)
using namespace std;
int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
return x*f;
}
const int maxn=100010;
const int maxnode=4000010;
typedef long long LL;
int n,m,rt,first[maxn],next[maxn],to[maxn],e;
void AddEdge(int u,int v) {
if(!u) rt=v;
to[++e]=v;next[e]=first[u];first[u]=e;
}
int s[maxnode],ls[maxnode],rs[maxnode],L[maxn],R[maxn],pos[maxn],sv[maxn],lv[maxn],cnt;
LL sumv[maxnode],ans;
void dfs(int x) {
L[x]=++cnt;pos[cnt]=x;
for(int i=first[x];i;i=next[i]) dfs(to[i]);
R[x]=cnt;
}
int root[maxn],ToT;
void build(int& y,int x,int l,int r,int pos) {
sumv[y=++ToT]=sumv[x]+pos;s[y]=s[x]+1;
if(l==r) return;
int mid=l+r>>1;ls[y]=ls[x];rs[y]=rs[x];
if(pos<=mid) build(ls[y],ls[x],l,mid,pos);
else build(rs[y],rs[x],mid+1,r,pos);
}
int query(int y,int x,int l,int r,int lim) {
if(l==r) return sumv[y]-sumv[x]?lim*(s[y]-s[x])/(sumv[y]-sumv[x]):0;
int mid=l+r>>1;
if(lim<=sumv[ls[y]]-sumv[ls[x]]) return query(ls[y],ls[x],l,mid,lim);
return query(rs[y],rs[x],mid+1,r,lim-sumv[ls[y]]+sumv[ls[x]])+s[ls[y]]-s[ls[x]];
}
int main() {
n=read();m=read();
rep(1,n) {
AddEdge(read(),i);
sv[i]=read();lv[i]=read();
}
dfs(rt);
rep(1,n) build(root[i],root[i-1],1,m,sv[pos[i]]);
rep(1,n) ans=max(ans,(LL)lv[i]*query(root[R[i]],root[L[i]-1],1,m,m));
printf("%lld\n",ans);
return 0;
}