//一个经典的树形背包,直接用剩余的时间对除主干路之外的其他路进行背包就可以了
//代码如下:
#include<stdio.h> #include<string.h> #define N 510 struct edge { int to,c,next; }edge[N*2]; int n,t,num[N],head[N],ant; void add(int a,int b,int c) { edge[ant].to=b; edge[ant].c=c; edge[ant].next=head[a]; head[a]=ant++; } int dp[N][N],next[N],sum; int find(int root,int parent) { int i,to,k; if(root==n) return 0; for(i=head[root];i!=-1;i=edge[i].next) { to=edge[i].to; if(to==parent)continue; k=find(to,root); if(k>=0) { next[root]=to; return k+edge[i].c; } } return -1; } int Max(int a,int b){return a<b?b:a;} void dfs(int root,int parent) { int i,to,k,j; dp[root][0]=num[root]; for(i=head[root];i!=-1;i=edge[i].next) { to=edge[i].to; if(to==parent)continue; dfs(to,root); for(j=t;j>0;j--) for(k=j;k>=0;k--) if(j-k-2*edge[i].c>=0) dp[root][j]=Max(dp[root][j],dp[root][k]+dp[to][j-k-2*edge[i].c]); } } int ans[N]; void dfs2(int root,int parent,int *ans) { int i,to,j,k; for(i=head[root];i!=-1;i=edge[i].next) { to=edge[i].to; if(to==parent) continue; if(to==next[root]) { sum+=num[to]; continue; } for(j=t;j>0;j--) for(k=j;k>=0;k--) if(j-k-2*edge[i].c>=0) ans[j]=Max(ans[j],ans[k]+dp[to][j-k-2*edge[i].c]); } if(next[root]>0) dfs2(next[root],root,ans); } int main() { int a,b,c,k,i; while(scanf("%d%d",&n,&t)!=EOF) { ant=0; memset(head,-1,sizeof(head)); for(i=1;i<=n-1;i++) { scanf("%d%d%d",&a,&b,&c); add(a,b,c); add(b,a,c); } for(i=1;i<=n;i++) scanf("%d",&num[i]); memset(next,-1,sizeof(next)); k=find(1,-1); if(t<k) printf("Human beings die in pursuit of wealth, and birds die in pursuit of food!\n"); else { sum=num[1]; t-=k; memset(dp,0,sizeof(dp)); dfs(1,-1); memset(ans,0,sizeof(ans)); dfs2(1,-1,ans); printf("%d\n",sum+ans[t]); } } return 0; }