#include #include #include using namespace std; vector> adj; vector dp; void dfs(int v, int parent){ //no return; for(auto x : adj[v]){ if(x == parent) continue; dfs(x, v); dp[v] = max(dp[v], dp[x] + 1); } } int main(){ int n; cin >> n; adj.resize(n, vector()); dp.resize(n, 1); vector visited(n, false); //这里节点从0开始到n - 1 for(int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } dfs(0, -1); int mmax = 0; if(adj[0].size() == 1) cout << dp[0] << endl; else{ vector tmp; for(auto x : adj[0]){ tmp.push_back(dp[x]); } sort(tmp.begin(), tmp.end()); mmax = *(tmp.end() - 1) + *(tmp.end() - 2); cout << mmax + 1<< endl; } return 0; } /* 7 0 1 0 2 1 3 1 4 2 5 2 6 8 0 1 0 2 1 3 1 4 2 5 2 6 3 7 */