#include <bits/stdc++.h>
using namespace std;
int INP, AM, REACHEOF;
char BUF[(1 << 12) + 1], *inp = BUF;
const long double PI = acos((long double)-1.0);
const int MN = 200111;
int n, q, now, getIn[MN], getOut[MN], sl[MN * 8], sum[MN * 8], res[MN];
vector<int> ke[MN];
vector<pair<int, int> > queries[MN];
void init() {
  for (int i = (1), _b = (n); i <= _b; i++) {
    ke[i].clear();
    queries[i].clear();
  }
  now = 0;
  memset(sum, 0, sizeof sum);
  memset(sl, 0, sizeof sl);
}
void dfs1(int u, int fu) {
  getIn[u] = ++now;
  for (int i = 0, _a = (ke[u].size()); i < _a; i++) {
    int v = ke[u][i];
    if (v == fu) continue;
    dfs1(v, u);
  }
  getOut[u] = now;
}
void update(int i, int l, int r, int u, int v, int k) {
  if (v < l || r < u) return;
  if (u <= l && r <= v) {
    sl[i] += k;
    if (sl[i] > 0)
      sum[i] = r - l + 1;
    else
      sum[i] = sum[((i) << 1)] + sum[(((i) << 1) + 1)];
    return;
  }
  int mid = (l + r) >> 1;
  update(((i) << 1), l, mid, u, v, k);
  update((((i) << 1) + 1), mid + 1, r, u, v, k);
  if (sl[i] == 0)
    sum[i] = sum[((i) << 1)] + sum[(((i) << 1) + 1)];
  else
    sum[i] = r - l + 1;
}
void dfs2(int u, int fu) {
  for (int i = 0, _a = (queries[u].size()); i < _a; i++) {
    int v = queries[u][i].first, w = queries[u][i].second;
    update(1, 1, n, getIn[v], getOut[v], +1);
    if (w != v) update(1, 1, n, getIn[w], getOut[w], +1);
  }
  res[u] = sum[1];
  if (res[u]) --res[u];
  for (int i = 0, _a = (ke[u].size()); i < _a; i++) {
    int v = ke[u][i];
    if (v == fu) continue;
    dfs2(v, u);
  }
  for (int i = 0, _a = (queries[u].size()); i < _a; i++) {
    int v = queries[u][i].first, w = queries[u][i].second;
    update(1, 1, n, getIn[v], getOut[v], -1);
    if (w != v) update(1, 1, n, getIn[w], getOut[w], -1);
  }
}
bool isAncestor(int u, int v) {
  return getIn[u] < getIn[v] && getOut[v] <= getOut[u];
}
int main() {
  while (scanf("%d%d", &n, &q) == 2) {
    init();
    for (int i = (2), _b = (n); i <= _b; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      ke[u].push_back(v);
      ke[v].push_back(u);
    }
    dfs1(1, -1);
    while (q--) {
      int a, b;
      scanf("%d%d", &a, &b);
      if (isAncestor(a, b)) {
        queries[a].push_back(make_pair(a, a));
      } else if (isAncestor(b, a)) {
        queries[b].push_back(make_pair(b, b));
      } else {
        queries[a].push_back(make_pair(a, b));
        queries[b].push_back(make_pair(a, b));
      }
    }
    dfs2(1, -1);
    for (int i = (1), _b = (n); i <= _b; i++) printf("%d ", res[i]);
    puts("");
  }
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

The Little Elephant loves trees very much, he especially loves root trees.

He's got a tree consisting of n nodes (the nodes are numbered from 1 to n), with root at node number 1. Each node of the tree contains some list of numbers which initially is empty. 

The Little Elephant wants to apply m operations. On the i-th operation (1 ≤ i ≤ m) he first adds number i to lists of all nodes of a subtree with the root in node number ai, and then he adds number i to lists of all nodes of the subtree with root in node bi.

After applying all operations the Little Elephant wants to count for each node i number ci — the number of integers j (1 ≤ j ≤ n; j ≠ i), such that the lists of the i-th and the j-th nodes contain at least one common number.

Help the Little Elephant, count numbers ci for him.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of the tree nodes and the number of operations. 

Each of the following n - 1 lines contains two space-separated integers, ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that mean that there is an edge between nodes number ui and vi. 

Each of the following m lines contains two space-separated integers, ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), that stand for the indexes of the nodes in the i-th operation.

It is guaranteed that the given graph is an undirected tree.

Output

In a single line print n space-separated integers — c1, c2, ..., cn.

Examples

Input

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


Output

0 3 3 3 3 

Input

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


Output

0 6 7 6 0 2 0 5 4 5 5 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int INP, AM, REACHEOF;
char BUF[(1 << 12) + 1], *inp = BUF;
const long double PI = acos((long double)-1.0);
const int MN = 200111;
int n, q, now, getIn[MN], getOut[MN], sl[MN * 8], sum[MN * 8], res[MN];
vector<int> ke[MN];
vector<pair<int, int> > queries[MN];
void init() {
  for (int i = (1), _b = (n); i <= _b; i++) {
    ke[i].clear();
    queries[i].clear();
  }
  now = 0;
  memset(sum, 0, sizeof sum);
  memset(sl, 0, sizeof sl);
}
void dfs1(int u, int fu) {
  getIn[u] = ++now;
  for (int i = 0, _a = (ke[u].size()); i < _a; i++) {
    int v = ke[u][i];
    if (v == fu) continue;
    dfs1(v, u);
  }
  getOut[u] = now;
}
void update(int i, int l, int r, int u, int v, int k) {
  if (v < l || r < u) return;
  if (u <= l && r <= v) {
    sl[i] += k;
    if (sl[i] > 0)
      sum[i] = r - l + 1;
    else
      sum[i] = sum[((i) << 1)] + sum[(((i) << 1) + 1)];
    return;
  }
  int mid = (l + r) >> 1;
  update(((i) << 1), l, mid, u, v, k);
  update((((i) << 1) + 1), mid + 1, r, u, v, k);
  if (sl[i] == 0)
    sum[i] = sum[((i) << 1)] + sum[(((i) << 1) + 1)];
  else
    sum[i] = r - l + 1;
}
void dfs2(int u, int fu) {
  for (int i = 0, _a = (queries[u].size()); i < _a; i++) {
    int v = queries[u][i].first, w = queries[u][i].second;
    update(1, 1, n, getIn[v], getOut[v], +1);
    if (w != v) update(1, 1, n, getIn[w], getOut[w], +1);
  }
  res[u] = sum[1];
  if (res[u]) --res[u];
  for (int i = 0, _a = (ke[u].size()); i < _a; i++) {
    int v = ke[u][i];
    if (v == fu) continue;
    dfs2(v, u);
  }
  for (int i = 0, _a = (queries[u].size()); i < _a; i++) {
    int v = queries[u][i].first, w = queries[u][i].second;
    update(1, 1, n, getIn[v], getOut[v], -1);
    if (w != v) update(1, 1, n, getIn[w], getOut[w], -1);
  }
}
bool isAncestor(int u, int v) {
  return getIn[u] < getIn[v] && getOut[v] <= getOut[u];
}
int main() {
  while (scanf("%d%d", &n, &q) == 2) {
    init();
    for (int i = (2), _b = (n); i <= _b; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      ke[u].push_back(v);
      ke[v].push_back(u);
    }
    dfs1(1, -1);
    while (q--) {
      int a, b;
      scanf("%d%d", &a, &b);
      if (isAncestor(a, b)) {
        queries[a].push_back(make_pair(a, a));
      } else if (isAncestor(b, a)) {
        queries[b].push_back(make_pair(b, b));
      } else {
        queries[a].push_back(make_pair(a, b));
        queries[b].push_back(make_pair(a, b));
      }
    }
    dfs2(1, -1);
    for (int i = (1), _b = (n); i <= _b; i++) printf("%d ", res[i]);
    puts("");
  }
  return 0;
}

```