#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define fir first
#define sec second
#define ll long long
#define pii pair<int, int>
#define mp make_pair

const int N = 2e5+10;
vector<int> es[N];

int n, k;
int d[N], ans[N], h[N];
queue<int> q;
vector<pii> vec;
priority_queue<pii> pq;
int main(){
    cin>>n;
    for(int i=1; i<n; i++){
        int u, v; scanf("%d%d",&u,&v);
        es[u].pb(v);
        es[v].pb(u);
    }
    memset(d, -1, sizeof(d));
    cin>>k;
    for(int i=1; i<=k; i++){
        int x; scanf("%d",&x);
        d[x] = 0; q.push(x);
    }
    while(!q.empty()){
        int x = q.front();  q.pop();
        for(auto &y: es[x]){
            if(d[y] != -1) continue;
            d[y] = d[x]+1;
            q.push(y);
        }
        vec.pb(pii{-d[x],x});
    }
    sort(vec.begin(),vec.end());

    memset(ans, 0, sizeof(ans));
    memset(h, 0, sizeof(h));
    for(int i=0; i<vec.size(); i++){
        int r=i; while(r+1<vec.size() && vec[r+1].fir == vec[i].fir) r++;
        int nw = -vec[i].fir;
        for(int j=i; j<=r; j++){
            int x=vec[j].sec;
            //cout<<x<<":"<<d[x]<<endl;
            ans[x] = max(ans[x], d[x]);
            if(d[x] > h[x]){
                h[x] = d[x];
                pq.push(pii{h[x]-1, x});
            }
        }
        i=r;
        while(!pq.empty()){
            int x = pq.top().sec;
            int t = pq.top().fir;
            //cout<<"  "<<x<<":"<<t<<endl;
            pq.pop();
            if(t == 0) continue;
            for(auto &y: es[x]){
                ans[y] = max(ans[y], nw);
                if(t > h[y]){
                    h[y] = t;
                    pq.push(pii{t-1,y});
                }
            }
        }
    }
    for(int i=1; i<=n; i++) printf("%d%c",ans[i]," \n"[i==n]);
    return 0;
}
	    	 									    		 		   		