#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #ifdef __unix__ #include #else #include "bits\stdc++.h" #endif #include #include #include #include #define REP(i,a,b) for(i=a;i connect[MAX]; int ans[MAX] = {0,0}; bool isleaf[MAX] = {0}; int INF = 1 << 30; void seek_depth() { int i; bool visited[MAX]={0}; queue qu; qu.push(1); visited[1] = true; while( not qu.empty() ) { int now = qu.front(); qu.pop(); rep(i,connect[now].size()) { int next = connect[now][i]; if( not visited[next] ) { visited[next] = true; ans[next] = ans[now]+1; qu.push(next); } } } } void seek_L(int leaf) { int i; queue qu; ans[leaf] = 0; qu.push(leaf); while( not qu.empty() ) { int now = qu.front(); qu.pop(); rep(i,connect[now].size()) { int next = connect[now][i]; if(ans[next] > ans[now]+1) { ans[next] = ans[now]+1; qu.push(next); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int i,j,k; cin >> N; rep(i,N-1) { int x,y; cin >> x >> y; connect[x].push_back(y); connect[y].push_back(x); } seek_depth(); for(i=1;i