#include #include #include #include using namespace atcoder; using namespace std; vector> Graph; vector checked; pair op(pair a,pair b){ return a>b?a:b; } pair e(){ return make_pair(-1,-1); } segtree,op,e> seg; int searched=0; int dfs(int i){ int pre=searched; searched++; checked[i]=true; for(int to:Graph[i]){ if(!checked[to]){ seg.set(to,make_pair(dfs(to),to)); } } int res=1; for(int j=0;j<2;j++){ pair tmp=seg.prod(pre,searched); if(tmp.first==-1){ break; } res+=tmp.first; seg.set(tmp.second,e()); } return res; } int main(){ int N; cin>>N; Graph.resize(N); checked.resize(N,false); for(int i=0;i>x>>y; Graph[x-1].push_back(y-1); Graph[y-1].push_back(x-1); } seg=segtree,op,e>(N); int ans=dfs(0); cout<