#include using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long ll; typedef pair mp; ll mod = 1e9+7; //LLONG_MIN /* やばい */ ll n,visit[2][100010]={},used[100010]={},d[2][100010],inf=1e18,ans=0; vector v[100010]; queue Q; void reset(ll p){ queue Q; Q.push(p); d[0][p]=inf; d[1][p]=inf; while(!Q.empty()){ p=Q.front();Q.pop(); for(ll q:v[p]){ if(used[q]==0 && d[0][q]!=inf){ d[0][q]=inf; d[1][q]=inf; Q.push(q); } } } // cout< Q; Q.push(p); d[m][p]=0; while(!Q.empty()){ p=Q.front();Q.pop(); for(ll q:v[p]){ if(used[q]==0 && d[m][q]>d[m][p]+1){ d[m][q]=d[m][p]+1; Q.push(q); } } } // cout< Q; Q.push(p); while(!Q.empty()){ p=Q.front();Q.pop(); for(ll q:v[p]){ if(used[q]==0){ if(d[m][largest] R; R.push(p); while(!R.empty()){ p=R.front();R.pop(); used[p]=1; // cout<>n; rep(i,n-1){ ll a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } ll p=1; Q.push(1); while(!Q.empty()){ ll p=Q.front();Q.pop(); reset(p); f(p,0); ll q=g(p,0);//最遠点1 reset(q); f(q,0); ll r=g(q,0);//最遠点2 f(r,1); h(q); // cout<