func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, t1, t2, cnt;   vector<int> mem[N];   int imp[N], hgt[N], res[N];   int p[N], noww[2 * N], goal[2 * N];   void link(int f, int t) {     noww[++cnt] = p[f];     goal[cnt] = t, p[f] = cnt;   }   void DFS(int nde, int fth) {     for (int i = p[nde]; i; i = noww[i])       if (goal[i] != fth) {         DFS(goal[i], nde);         if (hgt[nde] <= hgt[goal[i]])           hgt[nde] = hgt[goal[i]] + 1, imp[nde] = goal[i];       }     if (!imp[nde])       mem[nde].push_back(1);     else {       swap(mem[nde], mem[imp[nde]]), res[nde] = res[imp[nde]];       for (int i = p[nde]; i; i = noww[i])         if (goal[i] != fth && goal[i] != imp[nde]) {           int s1 = mem[nde].size(), s2 = mem[goal[i]].size();           for (int j = 0; j < s2; j++) {             mem[nde][s1 - s2 + j] += mem[goal[i]][j];             if (mem[nde][res[nde]] <= mem[nde][s1 - s2 + j])               res[nde] = s1 - s2 + j;           }         }       mem[nde].push_back(1);       if (mem[nde][res[nde]] == 1) res[nde] = mem[nde].size() - 1;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &t1, &t2);       link(t1, t2), link(t2, t1);     }     DFS(1, 0);     for (int i = 1; i <= n; i++) printf( %d n , hgt[i] - res[i]);     return 0;   }   