#include #include #include using namespace std; int main(){ int n; cin >> n; vector v[n]; int a, b; for(int i = 0; i < n-1; i++){ cin >> a >> b; a--, b--; v[a].push_back(b); v[b].push_back(a); } vector visit(n, 0); queue q; int t; q.push(0); while(!q.empty()){ int x = q.front(); q.pop(); if(visit[x]) continue; t = x; visit[x] = true; for(int next : v[x]){ if(!visit[next]) q.push(next); } } for(int i = 0; i < n; i++) visit[i] = false; queue> pq; pq.push({t, 0}); int cost; while(!pq.empty()){ auto x = pq.front(); pq.pop(); int i = x.first; if(visit[i]) continue; cost = x.second; visit[i] = true; for(int next : v[i]){ if(!visit[next]) pq.push({next, cost+1}); } } cout << n-1 - cost << endl; return 0; }