#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int __S = (1 << 20) + 5;
char __buf[__S], *__H, *__T;
inline char getc() {
  if (__H == __T) __T = (__H = __buf) + fread(__buf, 1, __S, stdin);
  if (__H == __T) return -1;
  return *__H++;
}
template <class __I>
inline void read(__I &__x) {
  __x = 0;
  int __fg = 1;
  char __c = getc();
  while (!isdigit(__c) && __c != '-') __c = getc();
  if (__c == '-') __fg = -1, __c = getc();
  while (isdigit(__c)) __x = __x * 10 + __c - '0', __c = getc();
  __x *= __fg;
}
inline void readd(double &__x) {
  __x = 0;
  double __fg = 1.0;
  char __c = getc();
  while (!isdigit(__c) && __c != '-') __c = getc();
  if (__c == '-') __fg = -1.0, __c = getc();
  while (isdigit(__c)) __x = __x * 10.0 + __c - '0', __c = getc();
  if (__c != '.') {
    __x = __x * __fg;
    return;
  } else
    while (!isdigit(__c)) __c = getc();
  double __t = 1e-1;
  while (isdigit(__c))
    __x = __x + 1.0 * (__c - '0') * __t, __t = __t * 0.1, __c = getc();
  __x = __x * __fg;
}
inline void reads(char *__s, int __x) {
  char __c = getc();
  int __tot = __x - 1;
  while (__c < '!' || __c > '~') __c = getc();
  while (__c >= '!' && __c <= '~') __s[++__tot] = __c, __c = getc();
  __s[++__tot] = '\0';
}
char __obuf[__S], *__oS = __obuf, *__oT = __oS + __S - 1, __c, __qu[55];
int __qr;
inline void flush() {
  fwrite(__obuf, 1, __oS - __obuf, stdout);
  __oS = __obuf;
}
inline void putc(char __x) {
  *__oS++ = __x;
  if (__oS == __oT) flush();
}
template <class __I>
inline void print(__I __x) {
  if (!__x) putc('0');
  if (__x < 0) putc('-'), __x = -__x;
  while (__x) __qu[++__qr] = __x % 10 + '0', __x /= 10;
  while (__qr) putc(__qu[__qr--]);
}
inline void prints(const char *__s, const int __x) {
  int __len = strlen(__s + __x);
  for (int __i = __x; __i < __len + __x; __i++) putc(__s[__i]);
}
inline void printd(double __x, int __d) {
  long long __t = (long long)floor(__x);
  print(__t);
  putc('.');
  __x -= (double)__t;
  while (__d--) {
    double __y = __x * 10.0;
    __x *= 10.0;
    int __c = (int)floor(__y);
    putc(__c + '0');
    __x -= floor(__y);
  }
}
inline void el() { putc('\n'); }
inline void sp() { putc(' '); }
}  // namespace IO
using namespace IO;
int cnt, sz[400005], usz[400005], n, x, y, g[400005], to[800005], he[400005],
    ne[800005], fm[400005], um[400005], sm[400005], ans[400005];
void dfs1(int x, int fa) {
  sz[x] = 1;
  for (int i = he[x], y; ~i; i = ne[i])
    if ((y = to[i]) != fa) {
      dfs1(y, x), sz[x] += sz[y];
      if (sz[y] > n / 2)
        g[x] = y, sm[x] = max(sm[x], fm[y]),
        sm[x] > fm[x] ? swap(sm[x], fm[x]) : void(0);
      else
        sm[x] = max(sm[x], sz[y]), sm[x] > fm[x] ? swap(sm[x], fm[x]) : void(0);
    }
  usz[x] = n - sz[x];
  if (usz[x] > n / 2) g[x] = -1;
}
void dfs2(int x, int fa) {
  if (usz[x] <= n / 2)
    um[x] = usz[x];
  else {
    if (fm[fa] == sz[x])
      um[x] = max(sm[fa], um[fa]);
    else
      um[x] = max(fm[fa], um[fa]);
  }
  for (int i = he[x], y; ~i; i = ne[i])
    if ((y = to[i]) != fa) dfs2(y, x);
}
void add(int x, int y) {
  to[cnt] = y;
  ne[cnt] = he[x];
  he[x] = cnt++;
}
int main() {
  memset(he, -1, sizeof(he));
  read(n);
  for (int i = 1; i < n; i++) read(x), read(y), add(x, y), add(y, x);
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    if (!g[i])
      ans[i] = 1;
    else if (g[i] == -1 && usz[i] - um[i] <= n / 2)
      ans[i] = 1;
    else if (g[i] != -1 && sz[g[i]] - fm[g[i]] <= n / 2)
      ans[i] = 1;
  }
  for (int i = 1; i <= n; i++) print(ans[i]), sp();
  flush();
}

### Prompt

Please provide a CPP coded solution 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;
namespace IO {
const int __S = (1 << 20) + 5;
char __buf[__S], *__H, *__T;
inline char getc() {
  if (__H == __T) __T = (__H = __buf) + fread(__buf, 1, __S, stdin);
  if (__H == __T) return -1;
  return *__H++;
}
template <class __I>
inline void read(__I &__x) {
  __x = 0;
  int __fg = 1;
  char __c = getc();
  while (!isdigit(__c) && __c != '-') __c = getc();
  if (__c == '-') __fg = -1, __c = getc();
  while (isdigit(__c)) __x = __x * 10 + __c - '0', __c = getc();
  __x *= __fg;
}
inline void readd(double &__x) {
  __x = 0;
  double __fg = 1.0;
  char __c = getc();
  while (!isdigit(__c) && __c != '-') __c = getc();
  if (__c == '-') __fg = -1.0, __c = getc();
  while (isdigit(__c)) __x = __x * 10.0 + __c - '0', __c = getc();
  if (__c != '.') {
    __x = __x * __fg;
    return;
  } else
    while (!isdigit(__c)) __c = getc();
  double __t = 1e-1;
  while (isdigit(__c))
    __x = __x + 1.0 * (__c - '0') * __t, __t = __t * 0.1, __c = getc();
  __x = __x * __fg;
}
inline void reads(char *__s, int __x) {
  char __c = getc();
  int __tot = __x - 1;
  while (__c < '!' || __c > '~') __c = getc();
  while (__c >= '!' && __c <= '~') __s[++__tot] = __c, __c = getc();
  __s[++__tot] = '\0';
}
char __obuf[__S], *__oS = __obuf, *__oT = __oS + __S - 1, __c, __qu[55];
int __qr;
inline void flush() {
  fwrite(__obuf, 1, __oS - __obuf, stdout);
  __oS = __obuf;
}
inline void putc(char __x) {
  *__oS++ = __x;
  if (__oS == __oT) flush();
}
template <class __I>
inline void print(__I __x) {
  if (!__x) putc('0');
  if (__x < 0) putc('-'), __x = -__x;
  while (__x) __qu[++__qr] = __x % 10 + '0', __x /= 10;
  while (__qr) putc(__qu[__qr--]);
}
inline void prints(const char *__s, const int __x) {
  int __len = strlen(__s + __x);
  for (int __i = __x; __i < __len + __x; __i++) putc(__s[__i]);
}
inline void printd(double __x, int __d) {
  long long __t = (long long)floor(__x);
  print(__t);
  putc('.');
  __x -= (double)__t;
  while (__d--) {
    double __y = __x * 10.0;
    __x *= 10.0;
    int __c = (int)floor(__y);
    putc(__c + '0');
    __x -= floor(__y);
  }
}
inline void el() { putc('\n'); }
inline void sp() { putc(' '); }
}  // namespace IO
using namespace IO;
int cnt, sz[400005], usz[400005], n, x, y, g[400005], to[800005], he[400005],
    ne[800005], fm[400005], um[400005], sm[400005], ans[400005];
void dfs1(int x, int fa) {
  sz[x] = 1;
  for (int i = he[x], y; ~i; i = ne[i])
    if ((y = to[i]) != fa) {
      dfs1(y, x), sz[x] += sz[y];
      if (sz[y] > n / 2)
        g[x] = y, sm[x] = max(sm[x], fm[y]),
        sm[x] > fm[x] ? swap(sm[x], fm[x]) : void(0);
      else
        sm[x] = max(sm[x], sz[y]), sm[x] > fm[x] ? swap(sm[x], fm[x]) : void(0);
    }
  usz[x] = n - sz[x];
  if (usz[x] > n / 2) g[x] = -1;
}
void dfs2(int x, int fa) {
  if (usz[x] <= n / 2)
    um[x] = usz[x];
  else {
    if (fm[fa] == sz[x])
      um[x] = max(sm[fa], um[fa]);
    else
      um[x] = max(fm[fa], um[fa]);
  }
  for (int i = he[x], y; ~i; i = ne[i])
    if ((y = to[i]) != fa) dfs2(y, x);
}
void add(int x, int y) {
  to[cnt] = y;
  ne[cnt] = he[x];
  he[x] = cnt++;
}
int main() {
  memset(he, -1, sizeof(he));
  read(n);
  for (int i = 1; i < n; i++) read(x), read(y), add(x, y), add(y, x);
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    if (!g[i])
      ans[i] = 1;
    else if (g[i] == -1 && usz[i] - um[i] <= n / 2)
      ans[i] = 1;
    else if (g[i] != -1 && sz[g[i]] - fm[g[i]] <= n / 2)
      ans[i] = 1;
  }
  for (int i = 1; i <= n; i++) print(ans[i]), sp();
  flush();
}

```