#include using namespace std; int main() { int n, k; cin >> n >> k; vector> g(n); for(int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; --u, --v; g[u].emplace_back(v); g[v].emplace_back(u); } vector has_acorn(n); int root = -1; for(int i = 0; i < k; i++) { int a; cin >> a; has_acorn[--a] = 1; root = a; } vector in_tree(n); auto dfs = [&](auto dfs, int now, int per) -> bool { bool f = has_acorn[now]; for(auto to : g[now]) { if(to == per) continue; f |= dfs(dfs, to, now); } return in_tree[now] = f; }; dfs(dfs, root, -1); int es = 0; for(int i = 0; i < n; i++) { for(auto to : g[i]) { if(in_tree[i] and in_tree[to]) { es++; } } } auto height = [&]() -> vector { auto bfs = [&](int s) { vector dist(n, 1 << 30); queue que; dist[s] = 0; que.push(s); while(!que.empty()) { int now = que.front(); que.pop(); for(auto to : g[now]) { if(!in_tree[to] or dist[to] != 1 << 30) continue; dist[to] = dist[now] + 1; que.push(to); } } return dist; }; auto vec1 = bfs(root); int v1 = -1, v2 = -1; int dia = -1; for(int i = 0; i < n; i++) if(dia < vec1[i] and in_tree[i]) dia = vec1[i], v1 = i; vec1 = bfs(v1); dia = -1; for(int i = 0; i < n; i++) if(dia < vec1[i] and in_tree[i]) dia = vec1[i], v2 = i; auto vec2 = bfs(v2); for(int i = 0; i < n; i++) if(vec1[i] < vec2[i]) vec1[i] = vec2[i]; return vec1; }; auto hei = height(); vector res(n); for(int i = 0; i < n; i++) { if(in_tree[i]) { res[i] = es - hei[i]; auto dfs = [&](auto dfs, int now, int per, int val) -> void { res[now] = val; for(auto to : g[now]) { if(to == per) continue; dfs(dfs, to, now, val + 1); } }; for(auto to : g[i]) { if(!in_tree[to]) { dfs(dfs, to, i, res[i] + 1); } } } } for(auto v : res) cout << v << '\n'; return 0; }