#include <bits/stdc++.h>
#define maxn 200005
#define mp std::make_pair
#define pii std::pair<int,int>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int inf = 1e8;

int size[maxn],n,a[maxn],k,dis[maxn],vis[maxn],rt,u,v,ans[maxn];
std::queue<int>q;
std::vector<pii>vec[maxn];
std::vector<int>ch[maxn];
std::vector<pii>S[maxn];

void dfsp(int u,int f=0){
	size[u]=1;
	for(int v:ch[u]){
		if(v==f||vis[v])continue;
		dfsp(v,u);
		size[u]+=size[v];
	}
}

void get_rt(int x,int f,int sum){
	int w=sum-size[x];
	for (int v:ch[x]){
		if(v==f||vis[v])continue;
		get_rt(v,x,sum);
		w=std::max(w,size[v]);
	}if(w<=sum/2)rt=x;
}

void dfs1(int u,int f,int dp,int to) {
	if (dis[u]-dp>0){
		ans[to]=std::max(ans[to],dis[u]);
		vec[to].push_back(mp(dis[u]-dp,dis[u]));
	}
	for (int v:ch[u]){
		if(v==f||vis[v])continue;
		dfs1(v,u,dp+1,to);
	}
}

void dfs2(int u,int f,int to,int d,int lim) {
	if (d >= lim || dis[u] == 0) return;
	auto p = std::upper_bound(S[to].begin(),S[to].end(),mp(d,inf));/// p--;
	//if (u ==4 && to == 1) { printf("->%d %d\n",d,(*p).second); }
	ans[u]=std::max(ans[u],(*p).second);
	//for (auto p:S[to]) if(d<p.first) ans[u]=std::max(ans[u],p.second);
	for (int v:ch[u]){
		if(v==f||vis[v])continue;
		dfs2(v,u,to,d+1,std::min(lim,dis[u]+d));
	}
}

void solve(int x) {
	rt = 0;
	dfsp(x);
	get_rt(x,0,size[x]);
	assert(rt);
	int u = rt;
	vis[u] = 1;
	for (int v:ch[u]) 
		if (!vis[v]) dfs1(v,u,1,u);
	vec[u].push_back(mp(inf,dis[u]));
	std::sort(vec[u].begin(),vec[u].end());
//	S[u].insert(mp(0,0));
	
	int pre = 0;
	for (int i = vec[u].size()-1;i>=0;i--) {
		auto p = vec[u][i];
		int x = p.first, y = std::max(pre,p.second);
	//	printf("%d %d\n",x,y);
		pre = std::max(pre,y);
		S[u].push_back(mp(x,y));
	} std::sort(S[u].begin(),S[u].end());
	for (int v:ch[u]) if (!vis[v]) dfs2(v,u,u,1,dis[u]);
	//for (int i = 1; i <= n; ++ i) printf("%d ",ans[i]); puts("");
	for (int v:ch[u])if(!vis[v])solve(v);
}

int read(){
	int x=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x;
}

int main() {
//	freopen("in.txt","r",stdin);
	scanf("%d",&n);
	for (int i = 1; i < n; ++ i) {
		u=read();v=read();
		ch[u].push_back(v);
		ch[v].push_back(u);
	} scanf("%d",&k);
	std::memset(dis,63,sizeof(dis));
	for (int i = 1; i <= k; ++ i) {
		a[i]=read();
		dis[a[i]] = 0;
		q.push(a[i]);
	} while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v:ch[u]) {
			if (dis[v] > dis[u] + 1) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	} for (int i =1;i<=n;++i)ans[i] = dis[i];//printf("%d ",dis[i]);puts(""); 
	solve(1);
	for (int i = 1; i <= n; ++ i) printf("%d ",ans[i]);
	return 0;
}



