#include using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector P(N); for (int i = 0; i < N; i++) { cin >> P[i]; } vector> g(N, vector()); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector C(M); for (int i = 0; i < M; i++) { cin >> C[i]; } vector dist(N, -1); queue> q; for (int i = 0; i < M; i++) { q.emplace(C[i], 0); } while (!q.empty()) { auto [n, d] = q.front(); q.pop(); if (dist[n] != -1) continue; dist[n] = d; for (int i = 0; i < g[n].size(); i++) { q.emplace(g[n][i], d + 1); } } vector deg(N); for (int i = 0; i < N; i++) { deg[i] = g[i].size(); } priority_queue, vector>> pq; for (int i = 0; i < N; i++) { if (dist[i] != 0 && deg[i] == 1) pq.emplace(P[i], dist[i], i); } ll ans = 0; int time = 0; while (!pq.empty()) { while (!pq.empty()) { auto [p, d, i] = pq.top(); if ( d > time ) { ans += p; pq.pop(); for (int j = 0; j < g[i].size(); j++) { deg[g[i][j]]--; if (deg[g[i][j]] == 1) { pq.emplace(P[g[i][j]], dist[g[i][j]], g[i][j]); } } break; } else { pq.pop(); } } time++; } cout << ans << endl; }