1 /*by SilverN*/
2 #include<algorithm>
3 #include<iostream>
4 #include<cstring>
5 #include<cstdio>
6 #include<cmath>
7 #include<vector>
8 #define LL long long
9 using namespace std;
10 const int mxn=100010;
11 int read(){
12 int x=0,f=1;char ch=getchar();
13 while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
14 while(ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
15 return x*f;
16 }
17 struct edge{
18 int v,nxt;
19 }e[mxn<<1];
20 int hd[mxn],mct=0;
21 void add_edge(int u,int v){
22 e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;return;
23 }
24 struct ninja{int fa;LL c,le;}a[mxn];
25 struct node{
26 int l,r;
27 LL w;
28 }t[mxn];
29 //
30 int n;LL m;
31 //可并堆
32 int fa[mxn],rt[mxn],size[mxn],cnt;
33 LL sum[mxn];
34 int find(int x){
35 if(fa[x]==x)return x;
36 return fa[x]=find(fa[x]);
37 }
38 int dep[mxn];
39 int mge(int x,int y){
40 if(x*y==0)return x+y;
41 if(t[x].w<t[y].w){swap(x,y);}//大根堆
42 t[x].r=mge(t[x].r,y);
43 if(dep[t[x].l]<dep[t[x].r])swap(t[x].l,t[x].r);
44 dep[x]=dep[t[x].r]+1;
45 return x;
46 }
47 void del(int &x){//
48 x=mge(t[x].l,t[x].r);
49 // fa[fa[x]]=fa[x];
50 return;
51 }
52 inline LL top(int x){
53 // int x=find(x);
54 return t[x].w;
55 }
56 //
57 LL ans=0;
58 void DFS(int u){
59 rt[u]=++cnt;
60 t[cnt].w=a[u].c;
61 sum[u]=a[u].c;
62 size[u]=1;
63 for(int i=hd[u];i;i=e[i].nxt){
64 int v=e[i].v;
65 DFS(v);
66 sum[u]+=sum[v];
67 size[u]+=size[v];
68 rt[u]=mge(rt[u],rt[v]);
69 }
70 while(sum[u]>m){//维护堆中sum小于M
71 sum[u]-=top(rt[u]);
72 del(rt[u]);size[u]--;
73 }
74 ans=max(ans,(LL)size[u]*a[u].le);
75 return;
76 }
77 int main(){
78 int i,j;
79 n=read();m=read();
80 for(i=1;i<=n;i++){
81 a[i].fa=read();
82 a[i].c=read();
83 a[i].le=read();
84 add_edge(a[i].fa,i);
85 }
86 DFS(1);
87 printf("%lld\n",ans);
88 return 0;
89 }