#include using namespace std; #ifdef LOCAL #include "../library/misc/debug.h" #else #define debug(...) 42 #endif // LOCAL int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int N; std::cin >> N; std::vector> adj(N); for (int i = 1; i < N; i++) { int u, v; std::cin >> u >> v; u--, v--; adj[u].push_back(v), adj[v].push_back(u); } int M; std::cin >> M; std::vector> S(N); std::vector> attack(N); std::vector exists(N); for (int i = 0; i < M; i++) { int u; std::cin >> u; u--; attack[u].push_back(u); exists[u] = true; for (auto &v : adj[u]) attack[v].push_back(u); } int tot = 0; for (int i = 0; i < N; i++) { tot += (!attack[i].empty()); if (attack[i].size() == 1U) S[attack[i][0]].insert(i); } debug(attack); debug(S); for (int i = 0; i < N; i++) { int ans = tot; if (attack[i].size() != 0U) ans--; for (auto &v : adj[i]) { if (attack[v].size()) { int now = exists[i] + exists[v]; if (attack[v].size() == now) ans--; } ans -= static_cast(S[v].size()); if (S[v].count(i)) ans++; if (S[v].count(v)) ans++; } std::cout << ans << "\n"; } }