func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 9;   const int inf = 1e9 + 9;   const long long mod = 1e9 + 7;   const int N = 4e5 + 9;   int n, u, v, ans[N], sub[N], mx[N], centroid;   vector<int> gr[N], c[N];   int dfs(int v, int f) {     sub[v] = 1;     for (int i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == f) continue;       int t = dfs(gr[v][i], v);       sub[v] += t;       mx[v] = max(mx[v], t);       c[v].push_back(t);     }     if ((n - sub[v]) <= n / 2 and mx[v] <= n / 2) {       ans[v] = 1;       centroid = v;     }     return sub[v];   }   void dfs2(int v, int f, int cur, int root) {     if (v != centroid and ans[v] == 0) {       int t = c[centroid].size() - 1;       if (sub[root] == c[centroid][t]) t--;       if (t >= 0 and n - sub[v] - c[centroid][t] <= n / 2)         ans[v] = 1;       else {         if (cur - sub[v] <= n / 2)           ans[v] = 1;         else           ans[v] = 0;       }     }     if (n - sub[v] <= n / 2) cur = sub[v];     for (int i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == f) continue;       if (v == centroid) root = gr[v][i];       dfs2(gr[v][i], v, cur, root);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       gr[u].push_back(v);       gr[v].push_back(u);     }     dfs(1, 0);     memset(mx, 0, sizeof mx);     for (int i = 1; i <= n; i++) c[i].clear();     dfs(centroid, 0);     for (int i = 1; i <= n; i++) sort(c[i].begin(), c[i].end());     dfs2(centroid, 0, 0, 0);     for (int i = 1; i <= n; i++) printf( %d n , ans[i]);     return 0;   }   