做法同 HDU 5290
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define mmt(a,v) memset(a,v,sizeof(a))
#define tra(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
const int N=500000+5;
const int inf=1e9;
struct Edge{int to,next;}e[N<<1];
int head[N],cnt;
void ins(int u,int v){e[++cnt]=(Edge){v,head[u]};head[u]=cnt;}
void insert(int u,int v){ins(u,v);ins(v,u);}
int f[N][25],g[N][25],d,w[N];
bool is[N];
void dp(int u,int fa){
g[u][d+1]=inf;
if(is[u])f[u][0]=g[u][0]=w[u];
rep(i,1,d)g[u][i]=w[u];
tra(i,u){
int v=e[i].to;if(v==fa)continue;
dp(v,u);
per(j,d,0)
g[u][j]=min(min(g[u][j]+f[v][j],g[v][j+1]+f[u][j+1]),g[u][j+1]);
f[u][0]=g[u][0];
rep(j,1,d+1)
f[u][j]=min(f[u][j-1],f[u][j]+f[v][j-1]);
}
}
int main(){
//freopen("a.in","r",stdin);
int n;scanf("%d%d",&n,&d);
rep(i,1,n)scanf("%d",&w[i]);
int m;scanf("%d",&m);
while(m--){int x;scanf("%d",&x);is[x]=true;}
rep(i,2,n){int u,v;scanf("%d%d",&u,&v);insert(u,v);}
dp(1,0);
printf("%d\n",f[1][0]);
return 0;
}