#include<bits/stdc++.h>
#define md ((l + r) >> 1)
#define lc p + 1
#define rc p + (md - l + 1) * 2
using namespace std;
const int N = 4e5 + 10, lg = 20;
struct edge {
  int to, nxt;
}e[N << 1];

int head[N], tot = 0;
int q[N], pa[N];
int n, k, mdis[N], dis[N], used[N], vis[N], siz[N];
int mxd[N], tmp[N], ans[N];
void adde(int u, int v) {
  e[++tot] = edge{v, head[u]};
  head[u] = tot;
}

int findc(int u) {
  int l, r;
  q[l = r = 1] = u;
  pa[u] = 0;
  while(l <= r) {
    int u = q[l++];
    siz[u] = 1;
    for(int i = head[u]; i; i = e[i].nxt) { 
      int v = e[i].to; 
      if(v == pa[u] || used[v]) continue; 
      q[++r] = v, pa[v] = u;
    }
  }
  for(int i = r; i >= 1; i--) {
    int u = q[i];
    if(siz[u] * 2 > r) return u;
    siz[pa[u]] += siz[u];
  }
}

void Bfs(vector<int> &p) {
  int l = 1, r = 0;
  for(int i = 1; i <= n; i++) mdis[i] = n * 2;
  for(int i = 0; i < (int)p.size(); i++) q[++r] = p[i], mdis[p[i]] = 0;
  while(l <= r) {
    int u = q[l++];
    for(int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if(mdis[v] <= mdis[u] + 1) continue;
      mdis[v] = mdis[u] + 1;
      q[++r] = v;
    }
  }
  return;
}

int bfs(int u) {
  int l, r;
  q[l = r = 1] = u;
  pa[u] = 0;
  dis[u] = 0;
  while(l <= r) {
    int u = q[l++];
    for(int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if(v == pa[u] || used[v]) continue;
      q[++r] = v, pa[v] = u;
    }
  }
  for(int i = 2; i <= r; i++) {
    int u = q[i];
    dis[u] = dis[pa[u]] + 1;
  }
  return r;
}

void solve(int r) {
  int mn = mdis[q[1]], mx = mdis[q[1]];
  for(int i = 2; i <= r; i++) {
    int u = q[i];
    mn = min(mn, mdis[u] - dis[u]);
    mx = max(mx, mdis[u] - dis[u]);
  }
  for(int i = 0; i <= r; i++) tmp[i] = 0;
  int h = mx - mn;
  for(int i = 0; i <= h + 1; i++) mxd[i] = 0;
  for(int i = 1; i <= r; i++) {
    int u = q[i];
    int p = mdis[u] - dis[u] - mn;
    mxd[p] = max(mxd[p], mdis[u]);
  }
  for(int i = h; i >= 0; i--) mxd[i] = max(mxd[i], mxd[i + 1]);
  for(int i = r; i >= 0; i--) {
    int p = max(0, i - mn + 1);
    if(h + mn - i > 0) tmp[i] = max(tmp[i], mxd[p]);
  }
  for(int i = 1; i <= r; i++) ans[q[i]] = max(ans[q[i]], tmp[dis[q[i]]]);
  return;
}

void work(int rt) {
  int c = findc(rt);
  int siz = bfs(c);
  solve(siz);
  used[c] = 1;
  for(int i = head[c]; i; i = e[i].nxt) {
    int v = e[i].to;
    if(used[v]) continue;
    work(v);
  }
  return;
}

int main() {
  scanf("%d", &n);
  for(int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adde(u, v), adde(v, u);
  }
  vector<int> p;
  scanf("%d", &k);
  p.resize(k);
  for(int i = 0; i < k; i++) scanf("%d", &p[i]);
  Bfs(p);
  work(1);
  for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
