#include #include using namespace std; using i64 = long long; int main() { i64 n; cin >> n; vector edge[n]; for (i64 i = 0; i < n - 1; i++) { i64 w, v; cin >> w >> v; edge[w].push_back(v); edge[v].push_back(w); } vector cnt(n); for (i64 i = 0; i < n; i++) cin >> cnt[i]; i64 q; cin >> q; for (i64 _ = 0; _ < q; _++) { i64 x; cin >> x; i64 ans = 0; queue que; vector far(n, 1e9); que.push(x); far[x] = 0; while (que.size()) { i64 p = que.front(); que.pop(); ans += cnt[p]; cnt[p] = 0; for (i64 i : edge[p]) if (far[p] < 2 && far[p] + 1 < far[i]) { far[i] = far[p] + 1; que.push(i); } } cnt[x] = ans; cout << ans << endl; } return 0; }