#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
struct nt {
	int ans;
	unordered_map<int, int> fa;
	unordered_map<int, int> fl;
	vector<pi> eg; 
	nt(){ans = 0;}
	int gfa(int a) {
		if (fa[a] == a) return a;
		return fa[a] = gfa(fa[a]);
	}
	void lk(int u, int v) {
		if (!fa[u]) fa[u] = u;
		if (!fa[v]) fa[v] = v;
		int uf = gfa(fa[u]), vf = gfa(fa[v]);
		if (uf == vf && fl[uf]) return ;
		eg.pb(mp(u, v));
		if (uf != vf && fl[uf] && fl[vf]) ans--;
		if (uf == vf) fl[uf] = 1;
		else {
			fa[uf] = vf;
			if (fl[uf]) fl[vf] = 1;
		}
		ans++; 
	}
};
vi eg[maxn];
int u[maxn], v[maxn];
int ans[maxn];
nt th[maxn];
void dfs(int a, int fa) {
	th[a].lk(u[a], v[a]);
//	cout << a << ' ' << th[a].ans << endl;
	for (auto x : eg[a]) {
		if (x == fa) continue;
		else {
			dfs(x, a);
			if (th[x].eg.size() > th[a].eg.size())
				swap(th[a], th[x]);
			for (auto q : th[x].eg)
				th[a].lk(q.fi, q.se);
		}
	}
	ans[a] = th[a].ans;
}
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		eg[x].pb(y), eg[y].pb(x); 
	}
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &u[i], &v[i]);
	dfs(1, 0);
	for (int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

