题意:
题解:
这题……阅读理解题吧。
既然只有loglog层,那么f[x][a][b]f[x][a][b]记忆化搜索下就好。
code:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
LL l[20010],r[20005];
LL f[20005][45][45],n;
LL a[40005],b[40005],c[40005];
LL dfs(LL x,LL X,LL Y)
{
if(x>=n) return c[x]*(a[x]+X)*(b[x]+Y);
if(f[x][X][Y]) return f[x][X][Y];
f[x][X][Y]=min(dfs(l[x],X+1,Y)+dfs(r[x],X,Y),dfs(l[x],X,Y)+dfs(r[x],X,Y+1));
return f[x][X][Y];
}
int main()
{
scanf("%lld",&n);
for(LL i=1;i<n;i++)
{
LL s,t;scanf("%lld %lld",&s,&t);
l[i]=s>0?s:n-s-1;r[i]=t>0?t:n-t-1;
}
for(LL i=n;i<2*n;i++) scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
printf("%lld",dfs(1,0,0));
}