#include <bits/stdc++.h>
using namespace std;
const int MAX = 400005;
struct Edge {
  int v, next;
} edge[MAX * 2];
int head[MAX];
int num[MAX];
int maxv[MAX];
int tot;
int n;
int up[MAX], down[MAX];
void init() {
  memset(head, -1, sizeof head);
  tot = 0;
}
void add_edge(int a, int b) {
  edge[tot] = (Edge){b, head[a]};
  head[a] = tot++;
}
void dfs1(int u, int fa) {
  num[u] = 1;
  maxv[u] = 0;
  up[u] = 0;
  down[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs1(v, u);
    num[u] += num[v];
    maxv[u] = max(maxv[u], maxv[v]);
    if (num[v] - maxv[v] > n / 2) down[u] = 0;
  }
  if (num[u] <= n / 2) maxv[u] = num[u];
}
void dfs2(int u, int fa, int d) {
  int cnt = 0;
  vector<int> st;
  st.push_back(0);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    st.push_back(v);
  }
  cnt = st.size() - 1;
  vector<int> pre(cnt + 5), suf(cnt + 5);
  for (int i = 1; i <= cnt; i++) pre[i] = max(pre[i - 1], maxv[st[i]]);
  for (int i = cnt; i > 0; i--) suf[i] = max(suf[i + 1], maxv[st[i]]);
  for (int i = 1; i <= cnt; i++)
    if (n - num[st[i]] - max(max(pre[i - 1], suf[i + 1]), d) <= n / 2)
      up[st[i]] = 1;
  for (int i = 1; i <= cnt; i++) {
    int k = d;
    k = max(max(pre[i - 1], suf[i + 1]), k);
    if (n - num[st[i]] <= n / 2) k = max(k, n - num[st[i]]);
    dfs2(st[i], u, k);
  }
}
int main() {
  while (cin >> n) {
    init();
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      add_edge(a, b);
      add_edge(b, a);
    }
    dfs1(1, -1);
    up[1] = 1;
    dfs2(1, -1, 0);
    for (int i = 1; i <= n; i++) {
      if (up[i] && down[i])
        printf("1");
      else
        printf("0");
      if (i == n)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed <image>.

You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.

Output

Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.

Examples

Input

3
1 2
2 3


Output

1 1 1 


Input

5
1 2
1 3
1 4
1 5


Output

1 0 0 0 0 

Note

In the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 400005;
struct Edge {
  int v, next;
} edge[MAX * 2];
int head[MAX];
int num[MAX];
int maxv[MAX];
int tot;
int n;
int up[MAX], down[MAX];
void init() {
  memset(head, -1, sizeof head);
  tot = 0;
}
void add_edge(int a, int b) {
  edge[tot] = (Edge){b, head[a]};
  head[a] = tot++;
}
void dfs1(int u, int fa) {
  num[u] = 1;
  maxv[u] = 0;
  up[u] = 0;
  down[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs1(v, u);
    num[u] += num[v];
    maxv[u] = max(maxv[u], maxv[v]);
    if (num[v] - maxv[v] > n / 2) down[u] = 0;
  }
  if (num[u] <= n / 2) maxv[u] = num[u];
}
void dfs2(int u, int fa, int d) {
  int cnt = 0;
  vector<int> st;
  st.push_back(0);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    st.push_back(v);
  }
  cnt = st.size() - 1;
  vector<int> pre(cnt + 5), suf(cnt + 5);
  for (int i = 1; i <= cnt; i++) pre[i] = max(pre[i - 1], maxv[st[i]]);
  for (int i = cnt; i > 0; i--) suf[i] = max(suf[i + 1], maxv[st[i]]);
  for (int i = 1; i <= cnt; i++)
    if (n - num[st[i]] - max(max(pre[i - 1], suf[i + 1]), d) <= n / 2)
      up[st[i]] = 1;
  for (int i = 1; i <= cnt; i++) {
    int k = d;
    k = max(max(pre[i - 1], suf[i + 1]), k);
    if (n - num[st[i]] <= n / 2) k = max(k, n - num[st[i]]);
    dfs2(st[i], u, k);
  }
}
int main() {
  while (cin >> n) {
    init();
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      add_edge(a, b);
      add_edge(b, a);
    }
    dfs1(1, -1);
    up[1] = 1;
    dfs2(1, -1, 0);
    for (int i = 1; i <= n; i++) {
      if (up[i] && down[i])
        printf("1");
      else
        printf("0");
      if (i == n)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}

```