func_code_string: #include <bits/stdc++.h>   using namespace std;   constexpr int N = 1e5 + 10;   int n, ans = 0;   int dp[N][2];   vector<int> g[N];   void chkmax(int &first, int second) {     if (first < second) first = second;   }   void dfs(int u, int fa) {     dp[u][0] = dp[u][1] = 0;     int flag = 0;     for (int &v : g[u]) {       if (v == fa) continue;       dfs(v, u);       chkmax(dp[u][0], max(dp[v][0], dp[v][1]));       chkmax(dp[u][1], dp[v][0]);     }     int deg = g[u].size();     if (dp[u][0] <= 0)       dp[u][0] += deg - 1;     else       dp[u][0] += deg - 2;     dp[u][1] += 1;     int pre = 0;     for (int &v : g[u]) {       if (v == fa) continue;       chkmax(ans, pre + max(dp[v][0], dp[v][1]) + deg - 2);       chkmax(pre, max(dp[v][0], dp[v][1]));     }     chkmax(ans, pre + deg - 1);     pre = 0;     for (int &v : g[u]) {       if (v == fa) continue;       chkmax(ans, pre + dp[v][0] + 1);       chkmax(pre, dp[v][0]);     }     chkmax(ans, pre + 1);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       g[u].push_back(v), g[v].push_back(u);     }     dfs(1, 0);     cout << ans << endl;     return 0;   }   