#include <bits/stdc++.h>
using namespace std;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
  return;
}
int main() {
  int n, Q;
  cin >> n >> Q;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += ans[x];
  }
  dfs(0);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
