#include #include #include #include using namespace std; using ull = unsigned long long; using ll = long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; vector> E; vector D; vector P; vector ans2; vector ans; void dfs(int p){ for(int e:E[p]) if(D[e]==-1){ P[e] = p; D[e] = D[p]+1; dfs(e); } } void dfs2(int p){ if(D[P[p]]==-1){ int e=P[p]; D[e]=0; ans2[e] = ans2[p] + 1; dfs2(e); ans2[p] = ans[e] + 1; } for(int e:E[p]) if(D[e]==-1){ D[e]=0; ans2[e] = ans2[p] + 1; dfs2(e); ans2[p] = ans[e] + 1; } ans[p] = ans2[p]; } int main(){ scanf("%d",&N); E.resize(N); rep(i,N-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; E[u].push_back(v); E[v].push_back(u); } D.assign(N,-1); P.assign(N,-1); D[0]=0; dfs(0); int s=0; rep(i,N) if(D[s]