graph g; pair f(ll i,ll p){ vector v; rep[g.edge[i]](j,g.es[i]){ if(j!=p){ auto r=f(j,i); v.push_back(r.first); v.push_back(r.second); } } sort(v.begin(),v.end()); v.push_back(0); v.push_back(0); v.push_back(0); return {v[0]+v[1]-1,v[2]}; } { ll@n; int a[n],b[]; rd((a,b)(n-1)); g.setEdge(n+1,n-1,a,b); auto r=f(1,1); wt(-r.first); }