#include typedef struct Edge { struct Edge *next; int v; } edge; void chmax(int* a, int b) { if (*a < b) *a = b; } void DFS(edge* adj[], int u, int par[], int size[], int max_depth[], int ans[]) { int w, max[2] = {-1, -1}; edge *p; for (p = adj[u], ans[u] = 0; p != NULL; p = p->next) { w = p->v; ans[u] += size[w]; if (max[0] < max_depth[w]) { max[1] = max[0]; max[0] = max_depth[w]; } else if (max[1] < max_depth[w]) max[1] = max_depth[w]; } ans[u] = ans[u] * 2 - max[0]; int tmp; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (w == par[u]) continue; if (max_depth[w] == 0) { size[w] = size[u] + 1; max_depth[w] = max_depth[u] + 1; DFS(adj, w, par, size, max_depth, ans); } else if (max_depth[w] == max[0]) { size[u] -= size[w]; size[w] += size[u]; tmp = max_depth[u]; max_depth[u] = max[1] + 1; if (max_depth[u] > 0) chmax(&(max_depth[w]), max_depth[u] + 1); DFS(adj, w, par, size, max_depth, ans); size[w] -= size[u]; size[u] += size[w]; max_depth[u] = tmp; } else { size[u] -= size[w]; size[w] += size[u]; tmp = max_depth[u]; max_depth[u] = max[0] + 1; max_depth[w] = max_depth[u] + 1; DFS(adj, w, par, size, max_depth, ans); size[w] -= size[u]; size[u] += size[w]; max_depth[u] = tmp; } } } int main() { int i, N, K, u, w, D[100001] = {}; edge *adj[100001] = {}, e[200001], *p; scanf("%d %d", &N, &K); for (i = 0; i < N - 1; i++) { scanf("%d %d", &u, &w); e[i*2].v = w; e[i*2+1].v = u; e[i*2].next = adj[u]; e[i*2+1].next = adj[w]; adj[u] = &(e[i*2]); adj[w] = &(e[i*2+1]); } for (i = 1; i <= K; i++) { scanf("%d", &u); D[u] = 1; } int par[100001] = {}, q[100001], head, tail; par[1] = 1; q[0] = 1; for (head = 0, tail = 1; head < tail; head++) { u = q[head]; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (par[w] == 0) { par[w] = u; q[tail++] = w; } } } int size[100001] = {}, max_depth[100001] = {}; for (head--; head >= 0; head--) { u = q[head]; if (size[u] == 0) size[u] += D[u]; else size[u]++; if (u != 1) size[par[u]] += size[u]; if (size[u] != 0) { chmax(&(max_depth[u]), 1); if (u != 1) chmax(&(max_depth[par[u]]), max_depth[u] + 1); } } int ans[100001]; DFS(adj, 1, par, size, max_depth, ans); for (u = 1; u <= N; u++) printf("%d\n", ans[u]); fflush(stdout); return 0; }