#include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = 1000000007; // 998244353 const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ using CostType = long long; struct Edge { int src, dst; CostType cost; Edge(int src_, int dst_, CostType cost_ = 0) : src(src_), dst(dst_), cost(cost_) {} inline bool operator<(const Edge &rhs) const { return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src; } inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; } inline bool operator>(const Edge &rhs) const { return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src; } inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; } }; struct DoubleSweep { using Pci = pair; int s, t; CostType diameter; DoubleSweep(const vector > &graph_) : graph(graph_) { Pci tmp1 = dfs(-1, 0); s = tmp1.second; Pci tmp2 = dfs(-1, tmp1.second); t = tmp2.second; diameter = tmp2.first; } private: vector > graph; Pci dfs(int par, int ver) { Pci res = {0, ver}; for (Edge e : graph[ver]) if (e.dst != par) { Pci result = dfs(ver, e.dst); result.first += e.cost; if (result.first > res.first) res = result; } return res; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n; cin >> n; vector > graph(n); REP(i, n - 1) { int a, b; cin >> a >> b; --a; --b; graph[a].emplace_back(Edge(a, b, 1)); graph[b].emplace_back(Edge(b, a, 1)); } DoubleSweep ds(graph); cout << n - 1 - ds.diameter << '\n'; return 0; }