#include using namespace std; using ll = long long; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) (void(0)) #endif void run_case(); int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; // cin >> T; while (T--) run_case(); return 0; } vector G[2 << 17]; pair dfs(int v, int p = - 1) { pair ret{0, v}; for(const auto&to: G[v]) if(to != p) { auto ch = dfs(to, v); ch.first += 1; ret = max(ret, ch); } return ret; } void run_case() { int N; cin >> N; for(int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); G[b].push_back(a); } auto D = dfs(0); D = dfs(D.second); int ans = 2 * (N - 1); ans -= D.first; cout << ans << endl; }