#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}


typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int d[MAXN]={};
vi val[MAXN];


vi cdist[MAXN];
int md[MAXN]={};

vi graph[MAXN];
int cparent[MAXN] = {};
int csize[MAXN] = {};
int vis[MAXN] = {}; 
// vis is marked at all higher level centroid
// used as bounday when dfs subgraph of a centroid

void get_dist(int i, int p, int d, int c) {
    cdist[i].push_back(d);
    md[c] = max(md[c], d);
    for(int j : graph[i]) {
        if(j != p && !vis[j]) {
            get_dist(j, i, d + 1,c);
        }
    }
}

int get_size(int i, int p) {
    int & res = csize[i] = 1;
    for(int j : graph[i])
        if(j != p && !vis[j])
            res += get_size(j, i);
    return res;
};
void get_centroid(int c, int cp = -1) { // cp->parent centroid
    int tot = get_size(c, -1);
    int pre = -1;
    while(1) {
        int to = -1;
        for(int j : graph[c]) {
            if(j != pre && !vis[j] && csize[j] * 2 > tot) {
                to = j;
                break;
            }
        }
        if(to == -1) break;
        pre = c;
        c = to;
    }
    cparent[c] = cp;
    vis[c]=1;
    for(int j : graph[c])
        if(!vis[j])
            get_centroid(j, c);
    vis[c]=0;
    get_dist(c, -1, 0,c); 
}


int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;
    int u,v;
    rep(i,0,n-1) {
        cin>>u>>v;
        graph[u].pb(v);
        graph[v].pb(u);
    }

    get_centroid(1);
    printn(cparent+1,n);
    printn(cdist+1,n);

    int k;
    cin>>k;
    queue<int> q;
    fill(d,d+n+1,-2);
    rep(i,0,k) {
        int tmp;
        cin>>tmp;
        q.push(tmp);
        d[tmp]=0;
    }

    int step=0;
    while(q.size()) {
        int len=q.size();
        while(len--){
            auto f=q.front();
            q.pop();
            d[f] = step;
            for(auto j:graph[f]) {
                if(d[j]==-2) {
                    d[j]=-1;
                    q.push(j);
                }
            }
        }
        step++;
    }
    print("bfs");

    rep(i,1,n+1) {
        if(d[i]==0) continue;
        int c = i, pos = 0;
        for(; c!=-1; c = cparent[c], pos++) {
            int tmpd = cdist[i][pos];
            if(tmpd >= d[i]) continue;
            tmpd = d[i] - 1 - tmpd;
            mini(tmpd, md[c]+1);
            if(val[c].size() < tmpd + 1)
                val[c].resize(tmpd + 1);
            val[c][tmpd] = max(val[c][tmpd], d[i]);
        }
    }
    printn(val+1,n);

    rep(i,1,n+1) {
        rrep(j,int(val[i].size())-2,-1) {
            val[i][j] = max(val[i][j], val[i][j+1]);
        }
    }

    vi res(n+1);
    rep(i,1,n+1) {
        if(d[i]==0) continue;

        int c = i, pos = 0;
        for(; c != -1; c = cparent[c], pos++) {
            int tmpd = cdist[i][pos];
            print(i,c,tmpd);

            // tmpd = min(tmpd, (int)val[c].size() - 1);
            mini(tmpd, md[c]);
            if(tmpd < val[c].size())
                res[i] = max(res[i], val[c][tmpd]);
        }
    }

    rep(i,1,n+1) {
        cout<<res[i]<<' ';
    }
    cout<<endl;




    return 0;
}

















### Prompt

Your challenge is to write a CPP solution to the following problem:

Alice and Bob are playing a game. They have a tree consisting of n vertices. Initially, Bob has k chips, the i-th chip is located in the vertex a_i (all these vertices are unique). Before the game starts, Alice will place a chip into one of the vertices of the tree.

The game consists of turns. Each turn, the following events happen (sequentially, exactly in the following order):

  1. Alice either moves her chip to an adjacent vertex or doesn't move it; 
  2. for each Bob's chip, he either moves it to an adjacent vertex or doesn't move it. Note that this choice is done independently for each chip. 



The game ends when Alice's chip shares the same vertex with one (or multiple) of Bob's chips. Note that Bob's chips may share the same vertex, even though they are in different vertices at the beginning of the game.

Alice wants to maximize the number of turns, Bob wants to minimize it. If the game ends in the middle of some turn (Alice moves her chip to a vertex that contains one or multiple Bob's chips), this turn is counted.

For each vertex, calculate the number of turns the game will last if Alice places her chip in that vertex.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of vertices in the tree.

Then n - 1 lines follow, each line contains two integers u_i, v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) that denote the endpoints of an edge. These edges form a tree.

The next line contains one integer k (1 ≤ k ≤ n - 1) — the number of Bob's chips.

The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n; a_i ≠ a_j if i ≠ j) — the vertices where the Bob's chips are initially placed.

Output

Print n integers. The i-th of them should be equal to the number of turns the game will last if Alice initially places her chip in the vertex i. If one of Bob's chips is already placed in vertex i, then the answer for vertex i is 0.

Examples

Input


5
2 4
3 1
3 4
3 5
2
4 5


Output


2 1 2 0 0


Input


8
4 1
8 4
4 5
6 4
2 5
4 3
1 7
3
2 8 3


Output


3 0 0 3 1 2 3 0


Input


10
2 5
4 3
7 3
7 2
5 8
3 6
8 10
7 9
7 1
4
10 6 9 1


Output


0 2 2 2 2 0 2 2 0 0

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}


typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int d[MAXN]={};
vi val[MAXN];


vi cdist[MAXN];
int md[MAXN]={};

vi graph[MAXN];
int cparent[MAXN] = {};
int csize[MAXN] = {};
int vis[MAXN] = {}; 
// vis is marked at all higher level centroid
// used as bounday when dfs subgraph of a centroid

void get_dist(int i, int p, int d, int c) {
    cdist[i].push_back(d);
    md[c] = max(md[c], d);
    for(int j : graph[i]) {
        if(j != p && !vis[j]) {
            get_dist(j, i, d + 1,c);
        }
    }
}

int get_size(int i, int p) {
    int & res = csize[i] = 1;
    for(int j : graph[i])
        if(j != p && !vis[j])
            res += get_size(j, i);
    return res;
};
void get_centroid(int c, int cp = -1) { // cp->parent centroid
    int tot = get_size(c, -1);
    int pre = -1;
    while(1) {
        int to = -1;
        for(int j : graph[c]) {
            if(j != pre && !vis[j] && csize[j] * 2 > tot) {
                to = j;
                break;
            }
        }
        if(to == -1) break;
        pre = c;
        c = to;
    }
    cparent[c] = cp;
    vis[c]=1;
    for(int j : graph[c])
        if(!vis[j])
            get_centroid(j, c);
    vis[c]=0;
    get_dist(c, -1, 0,c); 
}


int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;
    int u,v;
    rep(i,0,n-1) {
        cin>>u>>v;
        graph[u].pb(v);
        graph[v].pb(u);
    }

    get_centroid(1);
    printn(cparent+1,n);
    printn(cdist+1,n);

    int k;
    cin>>k;
    queue<int> q;
    fill(d,d+n+1,-2);
    rep(i,0,k) {
        int tmp;
        cin>>tmp;
        q.push(tmp);
        d[tmp]=0;
    }

    int step=0;
    while(q.size()) {
        int len=q.size();
        while(len--){
            auto f=q.front();
            q.pop();
            d[f] = step;
            for(auto j:graph[f]) {
                if(d[j]==-2) {
                    d[j]=-1;
                    q.push(j);
                }
            }
        }
        step++;
    }
    print("bfs");

    rep(i,1,n+1) {
        if(d[i]==0) continue;
        int c = i, pos = 0;
        for(; c!=-1; c = cparent[c], pos++) {
            int tmpd = cdist[i][pos];
            if(tmpd >= d[i]) continue;
            tmpd = d[i] - 1 - tmpd;
            mini(tmpd, md[c]+1);
            if(val[c].size() < tmpd + 1)
                val[c].resize(tmpd + 1);
            val[c][tmpd] = max(val[c][tmpd], d[i]);
        }
    }
    printn(val+1,n);

    rep(i,1,n+1) {
        rrep(j,int(val[i].size())-2,-1) {
            val[i][j] = max(val[i][j], val[i][j+1]);
        }
    }

    vi res(n+1);
    rep(i,1,n+1) {
        if(d[i]==0) continue;

        int c = i, pos = 0;
        for(; c != -1; c = cparent[c], pos++) {
            int tmpd = cdist[i][pos];
            print(i,c,tmpd);

            // tmpd = min(tmpd, (int)val[c].size() - 1);
            mini(tmpd, md[c]);
            if(tmpd < val[c].size())
                res[i] = max(res[i], val[c][tmpd]);
        }
    }

    rep(i,1,n+1) {
        cout<<res[i]<<' ';
    }
    cout<<endl;




    return 0;
}

















```