#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

class UF_pop{
    public:
    int sz;
    int sm;
    vector<int>par,nrank;
    vector<int> extra;
    vector<vector<int> > hist;
    UF_pop(int node_size) : sm(0),sz(node_size),par(sz),nrank(sz,0),extra(sz,0){
        rep(i,sz){
            par[i] = i;
        }
    }
    int find(int x){
        return (par[x] == x)?(x):find(par[x]);
    }
    void pop(){
        sm = 0;
        while(!hist.empty()){
            auto & a = hist.back();
            par[a[0]] = a[0],nrank[a[0]] = a[1],par[a[2]] = a[2];
            extra[a[0]] = 0;
            extra[a[2]] = 0;

            hist.pop_back();
        }
    }
    void unite(int x,int y){
        x = find(x); y = find(y);
        hist.push_back({x,nrank[x],y});
        if(x==y){
            if(extra[x]==0){
                extra[x]++;
                sm++;
            }else{
                extra[x]++;
            }
            return ;
        }
        //
        if(extra[x]==0||extra[y]==0){
            sm++;
        }
        if(nrank[x] < nrank[y]){
            par[x] = y;
            extra[y] += extra[x];
        }else{
            nrank[x] += (nrank[x]==nrank[y]);
            par[y] = x;
            extra[x] += extra[y];
        }
    }
    
};

int n,k;
vector<vector<int> > g;
vector<int> h;
vector<int> res;
vector<int> c;
vector<int> d;

int precalc(int id,int pre){
    int mx = -1;
    int sm = 0;
    for(int x:g[id]){
        if(x!=pre){
            int k = precalc(x,id);
            sm += k;
            if(mx<k){
                h[id] = x;
                mx = k;
            }
        }
    }
    sm++;
    return sm;
}
void dfs2(int id,int pre,UF_pop &uf){
    uf.unite(c[id],d[id]);
    for(auto x:g[id]){
        if(x!=pre){
            dfs2(x,id,uf);
        }
    }
    return;
}

void dfs(int id,int pre,UF_pop &uf){
    for(auto x:g[id]){
        if(x!=pre&&x!=h[id]){
            dfs(x,id,uf);
        }
        uf.pop();
    }
    if(h[id]!=-1)dfs(h[id],id,uf);
    uf.unite(c[id],d[id]);
    for(auto x:g[id]){
        if(x!=pre&&x!=h[id]){
            dfs2(x,id,uf);
        }
    }
    res[id] = uf.sm;
    return ;
}

int main(){
    cin >> n >> k;
    g.resize(n);
    h.resize(n,-1);
    res.resize(n);
    c.resize(n);
    d.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,n){
        cin >> c[i] >> d[i];
        c[i]--;d[i]--;
    }
    precalc(0,-1);
    // rep(i,n){
    //     cerr << h[i] << endl;
    // }
    UF_pop uf(k);
    dfs(0,-1,uf);
    rep(i,n){
        cout << res[i] << endl;
    }
    return 0;
}
