#include using namespace std; int main() { int n; cin >> n; vector> g(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].emplace_back(b); g[b].emplace_back(a); } vector dist(n, 1 << 30); dist[0] = 0; queue q; q.emplace(0); while (!q.empty()) { int x = q.front(); q.pop(); for (auto &next : g[x]) { if (dist[x] + 1 < dist[next]) { dist[next] = dist[x] + 1; q.emplace(next); } } } sort(dist.begin(), dist.end()); reverse(dist.begin(), dist.end()); cout << max(0, n - dist[0] - dist[1] - 1) << endl; return 0; }