#include namespace zawa { using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using i128 = __int128_t; using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using usize = std::size_t; } // namespace zawa namespace zawa { void SetFastIO() { std::cin.tie(nullptr)->sync_with_stdio(false); } void SetPrecision(u32 dig) { std::cout << std::fixed << std::setprecision(dig); } } // namespace zawa using namespace zawa; int main() { SetFastIO(); int n; std::cin >> n; std::vector g(n, std::vector{}); for (int _{} ; _ < n - 1 ; _++) { int a, b; std::cin >> a >> b; a--; b--; g[a].emplace_back(b); g[b].emplace_back(a); } std::vector pos(n, -1); int m; std::cin >> m; std::vector ghost(m); for (int i{} ; auto& gh : ghost) { std::cin >> gh; gh--; pos[gh] = i; i++; } std::vector count(n); for (int i{} ; i < n ; i++) if (pos[i] != -1) { count[i]++; for (auto x : g[i]) { count[x]++; } } std::vector unique(m, std::vector{}); for (int i{} ; i < n ; i++) if (pos[i] != -1) { int gh{pos[i]}; if (count[i] == 1) unique[gh].push_back(i); for (auto x : g[i]) { if (count[x] == 1) unique[gh].push_back(x); } } // for (auto x : count) std::cerr << x << ' '; // std::cerr << std::endl; int all{(int)std::ranges::count_if(count, [](const auto& i) -> bool { return i > 0; })}; for (int v{} ; v < n ; v++) { int ans{all}; if (pos[v] != -1) ans -= unique[pos[v]].size(); for (auto x : g[v]) if (pos[x] != -1) ans -= unique[pos[x]].size(); if (count[v] > 1) { ans--; } if (pos[v] != -1) { // std::cerr << v << " hello" << std::endl; for (auto x : g[v]) { // std::cerr << "travase " << x << std::endl; if (pos[x] == -1) continue; if (count[x] == 2) ans--; } } std::cout << ans << '\n'; } }