#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> g(n); vector deg(n), cnt(n), cnt2(n); for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x -= 1, y -= 1; g[x].push_back(y); g[y].push_back(x); } int m; cin >> m; vector f(n); for (int i = 0; i < m; i++) { int a; cin >> a; a -= 1; f[a] = true; for (int b : g[a]) { deg[b] += 1; } } int sum = 0; for (int i = 0; i < n; i++) { sum += (deg[i] >= 1 or f[i]); for (int t : g[i]) { cnt[i] += (deg[t] == 1); cnt2[i] += (deg[t] == 1 and !f[t]); } } for (int i = 0; i < n; i++) { int res = sum; if (deg[i] >= 1 or f[i]) res -= 1; if (f[i]) { res -= cnt[i]; for (int t : g[i]) { if (f[t]) { res -= cnt2[t]; } } cout << res << "\n"; } else { for (int t : g[i]) { if (f[t]) { res -= cnt2[t] + (deg[t] == 0); if (deg[i] == 1) res += 1; } } cout << res << "\n"; } } }