#include <bits/stdc++.h>
using namespace std;
inline void inp(long long int &n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  n = n * sign;
}
using namespace std;
long long int n;
const int MAXN = (long long int)4e5 + 10;
vector<long long int> v1[MAXN];
long long int toocool[MAXN];
long long int root;
long long int DFS(long long int curr, long long int par) {
  long long int ans = 1;
  for (long long int i = 0; i < v1[curr].size(); i++) {
    if (v1[curr][i] == par) continue;
    ans += DFS(v1[curr][i], curr);
  }
  return toocool[curr] = ans;
}
int find_centroid(int u, int p, int l) {
  for (int i = 0; i < v1[u].size(); i++) {
    int k = v1[u][i];
    if (k == p) continue;
    if (toocool[k] > (toocool[l] / 2)) return find_centroid(k, u, l);
  }
  return u;
}
int decompose(int i) {
  DFS(i, -1);
  int prev = find_centroid(i, -1, i);
  return prev;
}
long long int ans[MAXN], centroid1;
void DFS1(long long int u, long long int par, long long int mx) {
  if (u != centroid1) {
    if (n - toocool[u] - mx <= n / 2) ans[u] = 1;
  } else {
    ans[u] = 1;
  }
  long long int mx1 = 0;
  long long int mx2 = 0;
  long long int loc = -1;
  if (n - toocool[u] <= n / 2) mx1 = n - toocool[u];
  for (long long int i = 0; i < v1[u].size(); i++) {
    long long int k = v1[u][i];
    if (k == par) continue;
    if (toocool[k] > mx1) {
      mx2 = mx1;
      mx1 = toocool[k];
      loc = k;
    } else if (toocool[k] > mx2) {
      mx2 = toocool[k];
    }
  }
  for (long long int i = 0; i < v1[u].size(); i++) {
    long long int k = v1[u][i];
    if (k == par) continue;
    if (k == loc)
      DFS1(k, u, max(mx, mx2));
    else
      DFS1(k, u, max(mx, mx1));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    v1[x].push_back(y);
    v1[y].push_back(x);
  }
  centroid1 = decompose(1);
  DFS(centroid1, -1);
  DFS1(centroid1, -1, 0);
  for (long long int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

### Prompt

Create a solution in CPP for the following problem:

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;
inline void inp(long long int &n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  n = n * sign;
}
using namespace std;
long long int n;
const int MAXN = (long long int)4e5 + 10;
vector<long long int> v1[MAXN];
long long int toocool[MAXN];
long long int root;
long long int DFS(long long int curr, long long int par) {
  long long int ans = 1;
  for (long long int i = 0; i < v1[curr].size(); i++) {
    if (v1[curr][i] == par) continue;
    ans += DFS(v1[curr][i], curr);
  }
  return toocool[curr] = ans;
}
int find_centroid(int u, int p, int l) {
  for (int i = 0; i < v1[u].size(); i++) {
    int k = v1[u][i];
    if (k == p) continue;
    if (toocool[k] > (toocool[l] / 2)) return find_centroid(k, u, l);
  }
  return u;
}
int decompose(int i) {
  DFS(i, -1);
  int prev = find_centroid(i, -1, i);
  return prev;
}
long long int ans[MAXN], centroid1;
void DFS1(long long int u, long long int par, long long int mx) {
  if (u != centroid1) {
    if (n - toocool[u] - mx <= n / 2) ans[u] = 1;
  } else {
    ans[u] = 1;
  }
  long long int mx1 = 0;
  long long int mx2 = 0;
  long long int loc = -1;
  if (n - toocool[u] <= n / 2) mx1 = n - toocool[u];
  for (long long int i = 0; i < v1[u].size(); i++) {
    long long int k = v1[u][i];
    if (k == par) continue;
    if (toocool[k] > mx1) {
      mx2 = mx1;
      mx1 = toocool[k];
      loc = k;
    } else if (toocool[k] > mx2) {
      mx2 = toocool[k];
    }
  }
  for (long long int i = 0; i < v1[u].size(); i++) {
    long long int k = v1[u][i];
    if (k == par) continue;
    if (k == loc)
      DFS1(k, u, max(mx, mx2));
    else
      DFS1(k, u, max(mx, mx1));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    v1[x].push_back(y);
    v1[y].push_back(x);
  }
  centroid1 = decompose(1);
  DFS(centroid1, -1);
  DFS1(centroid1, -1, 0);
  for (long long int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

```