#include <bits/stdc++.h>
using namespace std;
namespace IO {
struct Scanner {
  bool hasNext = 1;
  bool hasRead = 1;
  int nextInt() {
    hasRead = 0;
    int res = 0;
    char flag = 1, ch = getchar();
    while (ch != EOF && !isdigit(ch)) {
      hasRead = 1;
      flag = (ch == '-') ? -flag : flag;
      ch = getchar();
    }
    while (ch != EOF && isdigit(ch)) {
      hasRead = 1;
      res = res * 10 + (ch - '0');
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return res * flag;
  }
  long long nextLL() {
    hasRead = 0;
    long long res = 0;
    char flag = 1, ch = getchar();
    while (ch != EOF && !isdigit(ch)) {
      hasRead = 1;
      flag = (ch == '-') ? -flag : flag;
      ch = getchar();
    }
    while (ch != EOF && isdigit(ch)) {
      hasRead = 1;
      res = res * 10 + (ch - '0');
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return res * flag;
  }
  char nextChar() {
    hasRead = 0;
    char ch = getchar();
    while (ch != EOF && isspace(ch)) {
      hasRead = 1;
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return ch;
  }
  int nextString(char *str) {
    hasRead = 0;
    int len = 0;
    char ch = getchar();
    while (ch != EOF && isspace(ch)) {
      hasRead = 1;
      ch = getchar();
    }
    while (ch != EOF && !isspace(ch)) {
      hasRead = 1;
      str[++len] = ch;
      ch = getchar();
    }
    str[len + 1] = 0;
    if (ch == EOF) hasNext = 0;
    return len;
  }
} sc;
long long rd() {
  long long x = sc.nextLL();
  return x;
}
void rd(int &x) { x = sc.nextInt(); }
void rd(long long &x) { x = sc.nextLL(); }
void rd(char &x) { x = sc.nextChar(); }
void rd(char *x) { sc.nextString(x); }
template <typename T1, typename T2>
void rd(pair<T1, T2> &x) {
  rd(x.first);
  rd(x.second);
}
template <typename T>
void rd(T *x, int n) {
  for (int i = 1; i <= n; ++i) rd(x[i]);
}
void printInt(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) printInt(x / 10);
  putchar('0' + x % 10);
}
void printLL(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) printLL(x / 10);
  putchar('0' + x % 10);
}
void pr(int x, char ch = '\n') {
  printInt(x);
  putchar(ch);
}
void pr(long long x, char ch = '\n') {
  printLL(x);
  putchar(ch);
}
template <typename T1, typename T2>
void pr(pair<T1, T2> x, char ch = '\n') {
  pr(x.first, ' ');
  pr(x.second, ch);
}
template <typename T>
void pr(T *x, int n) {
  for (int i = 1; i <= n; ++i) pr(x[i], " \n"[i == n]);
}
template <typename T>
void pr(vector<T> &x) {
  int n = x.size();
  for (int i = 1; i <= n; ++i) pr(x[i - 1], " \n"[i == n]);
}
}  // namespace IO
using namespace IO;
template <typename T>
void cmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T y) {
  if (y > x) x = y;
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1000000007;
int n;
vector<int> G[400005];
int siz[400005];
int X[400005];
int Xfrom[400005];
int Y1[400005];
int Y2[400005];
int ans[400005];
struct MAX2 {
  int max1, max2;
  void Init() { max1 = -INF, max2 = -INF; }
  void Insert(int v) {
    if (v > max2) {
      max2 = v;
      if (max2 > max1) swap(max1, max2);
    }
  }
  int RemoveMax(int v) {
    if (v == max1) return max2;
    return max1;
  }
} Y3[400005];
void dfs1(int u, int p) {
  siz[u] = 1;
  for (int v : G[u]) {
    if (v == p) continue;
    dfs1(v, u);
    siz[u] += siz[v];
  }
  X[u] = n - siz[u];
  Xfrom[u] = p;
  for (int v : G[u]) {
    if (v == p) continue;
    if (siz[v] > X[u]) {
      X[u] = siz[v];
      Xfrom[u] = v;
    }
  }
  if (X[u] <= n / 2) ans[u] = 1;
  if (siz[u] <= n / 2)
    Y1[u] = siz[u];
  else {
    for (int v : G[u]) {
      if (v == p) continue;
      cmax(Y1[u], Y1[v]);
    }
  }
  for (int v : G[u]) {
    if (v == p) continue;
    Y3[u].Insert(Y1[v]);
  }
}
void dfs2(int u, int p) {
  if (n - siz[u] <= n / 2) Y2[u] = n - siz[u];
  if (p) {
    cmax(Y2[u], Y2[p]);
    cmax(Y2[u], Y3[p].RemoveMax(Y1[u]));
  }
  for (int v : G[u]) {
    if (v == p) continue;
    dfs2(v, u);
  }
}
void dfs3(int u, int p) {
  if (ans[u] == 0) {
    if (Xfrom[u] == p) {
      if (n - siz[u] - Y2[u] <= n / 2) ans[u] = 1;
    } else {
      int v = Xfrom[u];
      if (siz[v] - Y1[v] <= n / 2) ans[u] = 1;
    }
  }
  for (int v : G[u]) {
    if (v == p) continue;
    dfs3(v, u);
  }
}
struct Solver {
  int t = INF;
  void InitOnce() {}
  void Read() {
    rd(n);
    for (int i = 1; i <= n; ++i) {
      G[i].clear();
      X[i] = 0;
      siz[i] = 0;
      Y1[i] = 0;
      Y2[i] = 0;
      Y3[i].Init();
      ans[i] = 0;
    }
    for (int i = 1; i <= n - 1; ++i) {
      int u, v;
      rd(u), rd(v);
      G[u].emplace_back(v), G[v].emplace_back(u);
    }
  }
  void Solve() {
    dfs1(1, 0);
    dfs2(1, 0);
    dfs3(1, 0);
    pr(ans, n);
  }
} solver;
int main() {
  solver.InitOnce();
  while (solver.t--) {
    solver.Read();
    if (!sc.hasRead) break;
    solver.Solve();
    if (!sc.hasNext) break;
  }
  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;
namespace IO {
struct Scanner {
  bool hasNext = 1;
  bool hasRead = 1;
  int nextInt() {
    hasRead = 0;
    int res = 0;
    char flag = 1, ch = getchar();
    while (ch != EOF && !isdigit(ch)) {
      hasRead = 1;
      flag = (ch == '-') ? -flag : flag;
      ch = getchar();
    }
    while (ch != EOF && isdigit(ch)) {
      hasRead = 1;
      res = res * 10 + (ch - '0');
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return res * flag;
  }
  long long nextLL() {
    hasRead = 0;
    long long res = 0;
    char flag = 1, ch = getchar();
    while (ch != EOF && !isdigit(ch)) {
      hasRead = 1;
      flag = (ch == '-') ? -flag : flag;
      ch = getchar();
    }
    while (ch != EOF && isdigit(ch)) {
      hasRead = 1;
      res = res * 10 + (ch - '0');
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return res * flag;
  }
  char nextChar() {
    hasRead = 0;
    char ch = getchar();
    while (ch != EOF && isspace(ch)) {
      hasRead = 1;
      ch = getchar();
    }
    if (ch == EOF) hasNext = 0;
    return ch;
  }
  int nextString(char *str) {
    hasRead = 0;
    int len = 0;
    char ch = getchar();
    while (ch != EOF && isspace(ch)) {
      hasRead = 1;
      ch = getchar();
    }
    while (ch != EOF && !isspace(ch)) {
      hasRead = 1;
      str[++len] = ch;
      ch = getchar();
    }
    str[len + 1] = 0;
    if (ch == EOF) hasNext = 0;
    return len;
  }
} sc;
long long rd() {
  long long x = sc.nextLL();
  return x;
}
void rd(int &x) { x = sc.nextInt(); }
void rd(long long &x) { x = sc.nextLL(); }
void rd(char &x) { x = sc.nextChar(); }
void rd(char *x) { sc.nextString(x); }
template <typename T1, typename T2>
void rd(pair<T1, T2> &x) {
  rd(x.first);
  rd(x.second);
}
template <typename T>
void rd(T *x, int n) {
  for (int i = 1; i <= n; ++i) rd(x[i]);
}
void printInt(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) printInt(x / 10);
  putchar('0' + x % 10);
}
void printLL(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) printLL(x / 10);
  putchar('0' + x % 10);
}
void pr(int x, char ch = '\n') {
  printInt(x);
  putchar(ch);
}
void pr(long long x, char ch = '\n') {
  printLL(x);
  putchar(ch);
}
template <typename T1, typename T2>
void pr(pair<T1, T2> x, char ch = '\n') {
  pr(x.first, ' ');
  pr(x.second, ch);
}
template <typename T>
void pr(T *x, int n) {
  for (int i = 1; i <= n; ++i) pr(x[i], " \n"[i == n]);
}
template <typename T>
void pr(vector<T> &x) {
  int n = x.size();
  for (int i = 1; i <= n; ++i) pr(x[i - 1], " \n"[i == n]);
}
}  // namespace IO
using namespace IO;
template <typename T>
void cmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T y) {
  if (y > x) x = y;
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1000000007;
int n;
vector<int> G[400005];
int siz[400005];
int X[400005];
int Xfrom[400005];
int Y1[400005];
int Y2[400005];
int ans[400005];
struct MAX2 {
  int max1, max2;
  void Init() { max1 = -INF, max2 = -INF; }
  void Insert(int v) {
    if (v > max2) {
      max2 = v;
      if (max2 > max1) swap(max1, max2);
    }
  }
  int RemoveMax(int v) {
    if (v == max1) return max2;
    return max1;
  }
} Y3[400005];
void dfs1(int u, int p) {
  siz[u] = 1;
  for (int v : G[u]) {
    if (v == p) continue;
    dfs1(v, u);
    siz[u] += siz[v];
  }
  X[u] = n - siz[u];
  Xfrom[u] = p;
  for (int v : G[u]) {
    if (v == p) continue;
    if (siz[v] > X[u]) {
      X[u] = siz[v];
      Xfrom[u] = v;
    }
  }
  if (X[u] <= n / 2) ans[u] = 1;
  if (siz[u] <= n / 2)
    Y1[u] = siz[u];
  else {
    for (int v : G[u]) {
      if (v == p) continue;
      cmax(Y1[u], Y1[v]);
    }
  }
  for (int v : G[u]) {
    if (v == p) continue;
    Y3[u].Insert(Y1[v]);
  }
}
void dfs2(int u, int p) {
  if (n - siz[u] <= n / 2) Y2[u] = n - siz[u];
  if (p) {
    cmax(Y2[u], Y2[p]);
    cmax(Y2[u], Y3[p].RemoveMax(Y1[u]));
  }
  for (int v : G[u]) {
    if (v == p) continue;
    dfs2(v, u);
  }
}
void dfs3(int u, int p) {
  if (ans[u] == 0) {
    if (Xfrom[u] == p) {
      if (n - siz[u] - Y2[u] <= n / 2) ans[u] = 1;
    } else {
      int v = Xfrom[u];
      if (siz[v] - Y1[v] <= n / 2) ans[u] = 1;
    }
  }
  for (int v : G[u]) {
    if (v == p) continue;
    dfs3(v, u);
  }
}
struct Solver {
  int t = INF;
  void InitOnce() {}
  void Read() {
    rd(n);
    for (int i = 1; i <= n; ++i) {
      G[i].clear();
      X[i] = 0;
      siz[i] = 0;
      Y1[i] = 0;
      Y2[i] = 0;
      Y3[i].Init();
      ans[i] = 0;
    }
    for (int i = 1; i <= n - 1; ++i) {
      int u, v;
      rd(u), rd(v);
      G[u].emplace_back(v), G[v].emplace_back(u);
    }
  }
  void Solve() {
    dfs1(1, 0);
    dfs2(1, 0);
    dfs3(1, 0);
    pr(ans, n);
  }
} solver;
int main() {
  solver.InitOnce();
  while (solver.t--) {
    solver.Read();
    if (!sc.hasRead) break;
    solver.Solve();
    if (!sc.hasNext) break;
  }
  return 0;
}

```