#include <bits/stdc++.h>
using std::vector;
const int maxn = 1e6 + 1;
vector<int> e[maxn], to[maxn];
struct Segment_Tree {
  int val[maxn << 2], cnt[maxn << 2];
  inline void pushup(int rt, int l, int r) {
    if (cnt[rt])
      val[rt] = (r - l + 1);
    else
      val[rt] = val[rt << 1] + val[rt << 1 | 1];
  }
  inline void update(int rt, int l, int r, int L, int R, int c) {
    if (L <= l && r <= R) {
      cnt[rt] += c;
      pushup(rt, l, r);
      return;
    }
    if (L <= ((l + r) >> 1)) update(rt << 1, l, ((l + r) >> 1), L, R, c);
    if (R > ((l + r) >> 1)) update(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, c);
    pushup(rt, l, r);
  }
  inline int query(int rt, int l, int r, int k, int lj) {
    if (l == r) return (lj >= 1);
    if (k <= ((l + r) >> 1))
      return query(rt << 1, l, ((l + r) >> 1), k, lj + cnt[rt << 1]);
    else
      return query(rt << 1 | 1, ((l + r) >> 1) + 1, r, k,
                   lj + cnt[rt << 1 | 1]);
  }
} t;
int idx[maxn], siz[maxn], n, q, a, b, id, m, ans[maxn];
inline void dfs1(int x, int f) {
  idx[x] = ++id;
  siz[x] = 1;
  for (int v : e[x]) {
    if (v == f) continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }
}
inline void dfs2(int x, int f) {
  if (to[x].size()) t.update(1, 1, n, idx[x], idx[x] + siz[x] - 1, 1);
  for (int v : to[x]) {
    t.update(1, 1, n, idx[v], idx[v] + siz[v] - 1, 1);
  }
  ans[x] = t.val[1] - t.query(1, 1, n, idx[x], t.cnt[1]);
  for (int v : e[x]) {
    if (v == f) continue;
    dfs2(v, x);
  }
  if (to[x].size()) t.update(1, 1, n, idx[x], idx[x] + siz[x] - 1, -1);
  for (int v : to[x]) {
    t.update(1, 1, n, idx[v], idx[v] + siz[v] - 1, -1);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n - 1; i++)
    scanf("%d %d", &a, &b), e[a].push_back(b), e[b].push_back(a);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}

### 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 std::vector;
const int maxn = 1e6 + 1;
vector<int> e[maxn], to[maxn];
struct Segment_Tree {
  int val[maxn << 2], cnt[maxn << 2];
  inline void pushup(int rt, int l, int r) {
    if (cnt[rt])
      val[rt] = (r - l + 1);
    else
      val[rt] = val[rt << 1] + val[rt << 1 | 1];
  }
  inline void update(int rt, int l, int r, int L, int R, int c) {
    if (L <= l && r <= R) {
      cnt[rt] += c;
      pushup(rt, l, r);
      return;
    }
    if (L <= ((l + r) >> 1)) update(rt << 1, l, ((l + r) >> 1), L, R, c);
    if (R > ((l + r) >> 1)) update(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, c);
    pushup(rt, l, r);
  }
  inline int query(int rt, int l, int r, int k, int lj) {
    if (l == r) return (lj >= 1);
    if (k <= ((l + r) >> 1))
      return query(rt << 1, l, ((l + r) >> 1), k, lj + cnt[rt << 1]);
    else
      return query(rt << 1 | 1, ((l + r) >> 1) + 1, r, k,
                   lj + cnt[rt << 1 | 1]);
  }
} t;
int idx[maxn], siz[maxn], n, q, a, b, id, m, ans[maxn];
inline void dfs1(int x, int f) {
  idx[x] = ++id;
  siz[x] = 1;
  for (int v : e[x]) {
    if (v == f) continue;
    dfs1(v, x);
    siz[x] += siz[v];
  }
}
inline void dfs2(int x, int f) {
  if (to[x].size()) t.update(1, 1, n, idx[x], idx[x] + siz[x] - 1, 1);
  for (int v : to[x]) {
    t.update(1, 1, n, idx[v], idx[v] + siz[v] - 1, 1);
  }
  ans[x] = t.val[1] - t.query(1, 1, n, idx[x], t.cnt[1]);
  for (int v : e[x]) {
    if (v == f) continue;
    dfs2(v, x);
  }
  if (to[x].size()) t.update(1, 1, n, idx[x], idx[x] + siz[x] - 1, -1);
  for (int v : to[x]) {
    t.update(1, 1, n, idx[v], idx[v] + siz[v] - 1, -1);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n - 1; i++)
    scanf("%d %d", &a, &b), e[a].push_back(b), e[b].push_back(a);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}

```