#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define ll long long
#define inf 1e17
#define N 200005
using namespace std;
int n,t;
int head[N],ver[N*2],nxt[N*2],tot;
ll quan[N*2];
void add(int a,int b,ll c)
{
tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;quan[tot]=c;return ;
}
int fa[N],d[N];
ll s[N],p[N],q[N],l[N],dep[N],f[N];
void dfs(int x,int ff)
{
for(int i=head[x];i;i=nxt[i])
{
if(ver[i]==ff)continue;
dep[ver[i]]=dep[x]+quan[i];
d[ver[i]]=d[x]+1;
dfs(ver[i],x);
}
return ;
}
int mn,zhong;
int size[N],now,v[N];
void dffs(int x,int ff)
{
int mx=0;size[x]=1;
for(int i=head[x];i;i=nxt[i])
{
if(v[ver[i]]||ver[i]==ff)continue;
dffs(ver[i],x);
size[x]+=size[ver[i]];
if(size[ver[i]]>mx)mx=size[ver[i]];
}if(now-size[x]>mx)mx=now-size[x];
if(mx<mn)mn=mx,zhong=x;
return ;
}
int tp[N],top;
void dfss(int x,int ff)
{
for(int i=head[x];i;i=nxt[i])
{
if(v[ver[i]]||ver[i]==ff)continue;
tp[++top]=ver[i];
dfss(ver[i],x);
}
}
bool cmp(int x,int y)
{
return dep[x]-l[x]>dep[y]-l[y];
}
int g[N];int as[N],cnt;
double cj(ll x,ll y,ll xx,ll yy)
{
return (double)x*yy-(double)y*xx;
}
double xie[N];
void dp()
{
int pt=1;int r=0;
for(int i=1;i<=top;i++)
{
int x=tp[i];
while(pt!=cnt+1&&dep[x]-l[x]<=dep[as[pt]])
{
while(r>1&&cj(dep[as[g[r]]]-dep[as[pt]],f[as[g[r]]]-f[as[pt]],dep[as[g[r-1]]]-dep[as[pt]],f[as[g[r-1]]]-f[as[pt]])<=0)r--;
g[++r]=pt;
if(r!=1)xie[r]=(double)(f[as[pt]]-f[as[g[r-1]]])/(double)(dep[as[pt]]-dep[as[g[r-1]]]);
pt++;
}xie[1]=1e100;
if(!r)continue;
int ha=1,ta=r;
while(ha<=ta)
{
int mid=(ha+ta)>>1;
if(xie[mid]>=p[x])ha=mid+1;
else ta=mid-1;
}
f[x]=min(f[x],f[as[g[ta]]]+(dep[x]-dep[as[g[ta]]])*p[x]+q[x]);
}
}
int id;
void ds(int x,int ff)
{
size[x]=1;if(d[x]<mn)mn=d[x],id=x;
for(int i=head[x];i;i=nxt[i])
{
if(ver[i]==ff||v[ver[i]])continue;
ds(ver[i],x);
size[x]+=size[ver[i]];
}
}
void solve(int x)
{
now=size[x];mn=n+1;zhong=x;
dffs(x,-1);
int root=zhong;v[root]=1;mn=n+1;
ds(root,-1);int pp=id;
for(int i=head[root];i;i=nxt[i])
{
if(!v[ver[i]]&&ver[i]==fa[root])solve(ver[i]);
}
cnt=0;as[++cnt]=root;
for(int i=fa[root];i!=fa[pp];i=fa[i])
{
as[++cnt]=i;
if(dep[root]-dep[i]<=l[root])f[root]=min(f[root],f[i]+(dep[root]-dep[i])*p[root]+q[root]);
}
top=0;
dfss(root,-1);
sort(tp+1,tp+top+1,cmp);
dp();
for(int i=head[root];i;i=nxt[i])
{
if(!v[ver[i]])solve(ver[i]);
}
return ;
}
int main()
{
scanf("%d%d",&n,&t);
for(int i=2;i<=n;i++)
{
scanf("%d%lld%lld%lld%lld",&fa[i],&s[i],&p[i],&q[i],&l[i]);
add(fa[i],i,s[i]);add(i,fa[i],s[i]);
}
for(int i=2;i<=n;i++)f[i]=inf;
d[1]=1;dfs(1,-1);
size[1]=n;solve(1);
for(int i=2;i<=n;i++)
{
printf("%lld\n",f[i]);
}
return 0;
}