#include #include using namespace std; int n; vector G[100005]; int dist[100005]; void dfs(int v, int pre, int d) { dist[v] = d; for(int i = 0; i < G[v].size(); i++){ if(G[v][i] == pre) continue; dfs(G[v][i], v, d+1); } } int main(void) { cin >> n; int u, v; for(int i = 0; i < n-1; i++){ cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } dfs(1, -1, 0); int mx = 0, root; for(int i = 1; i <= n; i++){ if(mx < dist[i]){ mx = dist[i]; root = i; } } dfs(root, -1, 0); int dia = 0; for(int i = 1; i <= n; i++) dia = max(dia, dist[i]); cout << (n-1) - dia << endl; return 0; }