func_code_string: #include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, y = 1;     char ch =    ;     for (; (ch !=  -  && (ch >  9  || ch <  0 )); ch = getchar())       ;     if (ch ==  - ) y = -1, ch = getchar();     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     return x * y;   }   const int N = 1e6 + 10;   struct node {     int to, nex;   } e[N << 1];   int bgn[N], d[N], mx[N], son[N], ans[N], dfn[N], id[N], c[N];   int n, cnt, tot;   void add(int x, int y) {     e[++cnt] = (node){y, bgn[x]};     bgn[x] = cnt;   }   void dfs(int x, int fa) {     mx[x] = d[x] = d[fa] + 1;     for (register int i = bgn[x]; i; i = e[i].nex) {       int y = e[i].to;       if (y == fa) continue;       dfs(y, x);       if (mx[y] > mx[son[x]]) {         son[x] = y;         mx[x] = mx[y];       }     }   }   void ins(int &p, int x, int k) {     c[x] += k;     if (c[x] > c[p] || c[x] == c[p] && p > x) p = x;   }   void solve(int x, int fa) {     dfn[++tot] = x;     id[x] = tot;     if (son[x]) solve(son[x], x);     int p = ans[son[x]];     for (register int i = bgn[x]; i; i = e[i].nex) {       int y = e[i].to;       if (y == fa || y == son[x]) continue;       solve(y, x);       for (register int j = 0; j <= mx[y] - d[y]; ++j)         ins(p, id[x] + j + 1, c[id[y] + j]);     }     ins(p, id[x], 1);     ans[x] = p;   }   int main() {     int x, y, z, k;     n = read();     for (register int i = 1; i < n; ++i) {       x = read();       y = read();       add(x, y);       add(y, x);     }     dfs(1, 0);     solve(1, 0);     for (register int i = 1; i <= n; ++i) printf( %d n , ans[i] - id[i]);     return 0;   }   