func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const int M = 2 * N;   const long long MOD1 = 98764321261LL;   const long long MOD = 998244353LL;   inline int lowbit(int x) { return x & (-x); }   struct fenwick {     long long a[N];     int n;     void init(int n) {       for (int i = 0; i <= n; ++i) a[i] = 0;       this->n = n;     }     void add(int x, long long v) {       for (int i = x; i <= n; i += lowbit(i)) a[i] += v;     }     long long query(int x) {       long long ret = 0;       for (int i = x; i; i ^= lowbit(i)) ret += a[i];       return ret;     }     void rangeadd(int l, int r, long long v) {       add(l, v);       add(r + 1, -v);     }     long long rangequery(int l, int r) {       l = max(l, 1);       r = min(r, n);       if (r < l) return 0;       long long ret = query(r);       ret -= query(l - 1);       return ret;     }   };   inline long long powmod(long long x, long long y, long long MOD) {     long long ret = 1;     while (y) {       if (y & 1LL) ret = ret * x % MOD;       x = x * x % MOD;       y = y >> 1;     }     return ret;   }   struct graph {     int head[N], next[M], to[M];     int tot;     inline void init(int n) {       for (int i = 0; i <= n; ++i) head[i] = -1;       tot = 0;     }     inline void addedge(int x, int y) {       to[tot] = y;       next[tot] = head[x];       head[x] = tot;       ++tot;     }   };   struct point {     long long x, y;     point() {}     point(long long x, long long y) : x(x), y(y) {}     void read() { scanf( %lld%lld , &x, &y); }     point operator+(const point &rhs) const {       return point(x + rhs.x, y + rhs.y);     }     point operator-(const point &rhs) const {       return point(x - rhs.x, y - rhs.y);     }     long long operator^(const point &rhs) const { return x * rhs.y - y * rhs.x; }     bool operator<(const point &rhs) const {       if (y != rhs.y) return y < rhs.y;       return x < rhs.x;     }   };   long long phi(long long x) {     long long res = x;     for (long long i = 2; i * i <= x; ++i) {       if (x % i == 0) {         res = res / i * (i - 1);         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res / x * (x - 1);     return res;   }   int n, m;   int ans;   int a[N], b[N], deg[N];   graph G;   void dfs(int x, int p) {     a[x] = 1;     b[x] = 0;     int chcnt = 0;     int maxa = -1;     int maxb = -1;     for (int i = G.head[x]; i != -1; i = G.next[i]) {       int y = G.to[i];       if (y == p) continue;       dfs(y, x);       int temp;       if (maxa != -1) {         temp = a[maxa] + a[y] + deg[x] - 2;         ans = max(ans, temp);         temp = a[maxa] + b[y] + deg[x] - 2;         ans = max(ans, temp);       }       if (maxb != -1) {         temp = b[maxb] + b[y] + deg[x] - 2;         ans = max(ans, temp);         temp = b[maxb] + b[y] + 1;         ans = max(ans, temp);         temp = b[maxb] + a[y] + deg[x] - 2;         ans = max(ans, temp);       }       a[x] = max(a[x], b[y] + 1);       b[x] = max(b[x], a[y] + deg[x] - 1 - (p != 0));       b[x] = max(b[x], b[y] + deg[x] - 1 - (p != 0));       if (maxa == -1 || a[y] > a[maxa]) maxa = y;       if (maxb == -1 || b[y] > b[maxb]) maxb = y;     }     ans = max(ans, a[x]);     ans = max(ans, b[x] + (p != 0));   }   int main() {     int cases = 1;     for (int iii = 1; iii <= cases; ++iii) {       scanf( %d , &n);       G.init(n);       for (int i = 1; i < n; ++i) {         int x, y;         scanf( %d%d , &x, &y);         G.addedge(x, y);         G.addedge(y, x);         ++deg[x];         ++deg[y];       }       ans = 0;       dfs(1, 0);       printf( %d n , ans);     }   }   