func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int Mod = 1e9 + 7;   const int maxn = 500000;   struct edge {     int id, nxt;     edge() {}     edge(int _id, int _nxt) : id(_id), nxt(_nxt) {}   };   edge e[(maxn << 1) + 5];   int st[maxn + 5], en = 0;   inline void add_edge(int first, int second) {     e[en] = edge(second, st[first]), st[first] = en++;   }   int n;   set<pair<int, int> > all[maxn + 5];   int id[maxn + 5];   int sz[maxn + 5];   int dep[maxn + 5];   int ans = 0;   void dfs(int first, int f = -1) {     id[first] = first;     for (int i = st[first]; i != -1; i = e[i].nxt) {       int second = e[i].id;       if (second == f) continue;       dep[second] = dep[first] + 1;       dfs(second, first);       if (f == -1) {         chkmax(ans, (--all[id[second]].end())->first - 1);         continue;       }       if (sz[first] < sz[second]) swap(id[first], id[second]);       sz[first] += sz[second];       for (auto u : all[id[second]]) {         for (int v = (u.second), _end_ = (u.first); v < _end_; ++v) {           auto t = all[id[first]].lower_bound(make_pair(v, oo));           if (t == all[id[first]].end() || t->second > v)             all[id[first]].insert(make_pair(v + 1, v));           else {             auto t0 = t;             int from = t->second, to = t->first;             while (1) {               auto pre = t0++;               if (t0 == all[id[first]].end()) break;               if (pre->first < t0->second) break;               to = t0->first;             }             all[id[first]].erase(t, t0);             all[id[first]].insert(make_pair(to + 1, from));           }         }       }     }     if (!(int((all[id[first]]).size())))       all[id[first]].insert(make_pair(dep[first] + 1, dep[first])), sz[first] = 1;   }   int main() {     memset(st, -1, sizeof st), en = 0;     scanf( %d , &n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i) {       int first, second;       scanf( %d%d , &first, &second), --first, --second;       add_edge(first, second), add_edge(second, first);     }     dfs(0);     printf( %d n , ans);     return 0;   }   