#include #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pairP; class LCA{ public: vector>E; vector>par; vectord1; int MAX_LOG=18; int n; LCA(){} LCA(int N){ n=N; E=vector>(n); par=vector>(MAX_LOG,vector(n)); d1=vector(n); } void add_edge(int a,int b){ E[a].push_back(b); E[b].push_back(a); } private: void dfs(int u,int p,int a){ par[0][u]=p;d1[u]=a; for(auto&v:E[u]){ if(v!=p)dfs(v,u,a+1); } } bool flag=false; void init(){ dfs(0,-1,0); for(int i=1;id1[v])swap(u,v); for(int i=0;i>i&1)v=par[i][v]; } if(u==v)return u; for(int i=MAX_LOG-1;i>=0;i--){ if(par[i][u]!=par[i][v]){ u=par[i][u]; v=par[i][v]; } } return par[0][u]; } }; template class BIT{ public: vectorbit; T cnt; BIT(int n){ bit=vector(n+10); cnt=0; } void add(int k,T x){ k++; while(k<(int)bit.size()){ bit[k]+=x; k+=k&-k; } cnt+=x; } T sum(int k){ k++; T res=0; while(k){ res+=bit[k]; k-=k&-k; } return res; } T sum2(int k){ return cnt-sum(k); } }; LCA lca; int n,K; int c[200000]; ll d[200000]; int L[200000],R[200000];//lca from left,right int LR[200000]; // left+right end int b[200000]; ll suml[200000],sumr[200000]; int main(){ cin>>n>>K; lca=LCA(n); rep(i,K){ scanf("%d",&c[i]);c[i]--; } rep(i,K)scanf("%lld",&d[i]); rep(i,n-1){ int a,b;scanf("%d%d",&a,&b);a--;b--; lca.add_edge(a,b); } lca.lca(0,1); for(int i=K-1;i>=0;i--){ if(i==K-1)R[i]=c[i],sumr[i]=d[i]; else R[i]=lca.lca(R[i+1],c[i]),sumr[i]=sumr[i+1]+d[i]; } rep(i,K){ if(i==0)L[i]=c[i],suml[i]=d[i]; else L[i]=lca.lca(L[i-1],c[i]),suml[i]=suml[i-1]+d[i]; } vectorV; V.push_back(L[K-1]+suml[K-1]); rep(i,K)for(int j=i+1;j<=K;j++){ if(i==0){ if(j==K)V.push_back(LLONG_MIN); else V.push_back(lca.d1[R[j]]+sumr[j]); continue; } if(j==K){ V.push_back(lca.d1[L[i-1]]+suml[i-1]); continue; } V.push_back(lca.d1[lca.lca(L[i-1],R[j])]+suml[i-1]+sumr[j]); } sort(V.begin(),V.end()); //~ for(auto p:V)cout<