1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 using namespace std;
7 #define Maxn 100010
8 #define LL long long
9
10 struct node
11 {
12 int x,y,next;
13 }t[Maxn];int len=0;
14
15 int w[Maxn],rt[Maxn],first[Maxn];
16 int n,m;
17
18 int mymin(int x,int y) {return x<y?x:y;}
19 // int mymax(int x,int y) {return x>y?x:y;}
20 LL mymax(LL x,LL y) {return x>y?x:y;}
21
22 void ins(int x,int y)
23 {
24 t[++len].x=x;t[len].y=y;
25 t[len].next=first[x];first[x]=len;
26 }
27
28
29 int c[Maxn],lc[Maxn],rc[Maxn],dis[Maxn],siz[Maxn];
30 LL h[Maxn];
31 int merge(int x,int y)
32 {
33 if(x==0||y==0) return x+y;
34 if(c[x]<c[y]) swap(x,y);
35 rc[x]=merge(rc[x],y);
36 if(dis[lc[x]]<dis[rc[x]]) swap(lc[x],rc[x]);
37 h[x]=c[x]+h[lc[x]]+h[rc[x]];
38 siz[x]=siz[lc[x]]+siz[rc[x]]+1;
39 dis[x]=dis[rc[x]]+1;
40 return x;
41 }
42
43 int rtt(int x)
44 {
45 if(x==0) return 0;
46 if(x!=rt[x]) rt[x]=rtt(rt[x]);
47 return rt[x];
48 }
49
50 LL ans=0;
51 void ffind(int x)
52 {
53 for(int i=first[x];i;i=t[i].next) ffind(t[i].y);
54 int nw=rtt(x);
55 for(int i=first[x];i;i=t[i].next)
56 {
57 int xx=nw;
58 nw=merge(nw,rtt(t[i].y));
59 rt[xx]=rt[rtt(t[i].y)]=nw;
60 }
61 while(h[nw]>m)
62 {
63 int xx=nw;
64 nw=merge(lc[nw],rc[nw]);
65 rt[lc[xx]]=rt[rc[xx]]=nw;
66 rt[xx]=nw;
67 }
68 LL X=w[x],Y=siz[nw];
69 // ans=mymax(ans,(LL)w[x]*(LL)siz[nw]);
70 ans=mymax(ans,X*Y);
71 }
72
73 int main()
74 {
75 scanf("%d%d",&n,&m);
76 memset(first,0,sizeof(first));
77 int sum=0;dis[0]=-1;
78 for(int i=1;i<=n;i++)
79 {
80 int x,y,z;
81 scanf("%d%d%d",&x,&y,&z);
82 ins(x,i);c[i]=y;w[i]=z;
83 rt[i]=i;h[i]=c[i];siz[i]=1;
84 }
85 ffind(1);
86 printf("%lld\n",ans);
87 return 0;
88 }