#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; void solve(){ int n; cin >> n; vector> T(n); for(int i=0; i> u >> v; u--; v--; T[u].push_back(v); T[v].push_back(u); } vector dp1(n, 1); function dfs1 = [&](int v, int p) { for(int to : T[v]) if(to != p){ dfs1(to, v); dp1[v] = max(dp1[v], dp1[to]+1); } }; dfs1(0, -1); int ans = 0; vector dp2(n, 0); function dfs2 = [&](int v, int p) { { vector x; if(v != 0) x.pb(dp2[v]); for(int to : T[v]) if(to != p) x.pb(dp1[to]); sort(all(x), greater()); for(int i=0; i mst; mst.insert(dp2[v]); for(int to : T[v]) if(to != p) mst.insert(dp1[to]); for(int to : T[v]) if(to != p){ mst.erase(mst.find(dp1[to])); dp2[to] = 1 + (mst.empty() ? 0 : *mst.rbegin()); mst.insert(dp1[to]); } for(int to : T[v]) if(to != p) dfs2(to, v); }; dfs2(0, -1); cout << ans << '\n'; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }