1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 const int N=100050;
7 int gi()
8 {
9 int x=0;
10 char ch=getchar();
11 while(ch<‘0‘||ch>‘9‘) ch=getchar();
12 while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar();
13 return x;
14 }
15 struct Xheap
16 {
17 int v[N],l[N],r[N];
18 int merge(int x,int y)
19 {
20 if(x==0||y==0)return x+y;
21 if(v[x]<v[y])swap(x,y);
22 r[x]=merge(r[x],y);
23 swap(l[x],r[x]);
24 return x;
25 }
26 void pop(int &x){x=merge(l[x],r[x]);}
27 int top(int x){return v[x];}
28 }heap;
29 int head[N*2],to[N*2],nxt[N*2],L[N],c[N],n,m,tt;
30 int root[N];
31 long long ans,tot[N],size[N];
32 void lnk(int x,int y)
33 {
34 to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
35 to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
36 }
37 void dfs(int x,int f)
38 {
39 root[x]=x;size[x]=1;heap.v[x]=c[x];tot[x]=c[x];
40 for(int i=head[x];i;i=nxt[i])
41 {
42 int y=to[i];
43 if(y!=f)
44 {
45 dfs(y,x);
46 size[x]+=size[y];
47 tot[x]+=tot[y];
48 root[x]=heap.merge(root[x],root[y]);
49 }
50 }
51 while(tot[x]>m)
52 {
53 tot[x]-=heap.top(root[x]);heap.pop(root[x]);
54 size[x]--;
55 }
56 ans=max(ans,(long long)size[x]*(long long)L[x]);
57 }
58 int main()
59 {
60 n=gi(),m=gi();
61 int x;
62 for(int i=1;i<=n;i++) x=gi(),lnk(i,x),c[i]=gi(),L[i]=gi();
63 dfs(1,0);
64 printf("%lld",ans);
65 }