OI XXIII - nad

// https://szkopul.edu.pl/problemset/problem/sKmyIHBMNi9EV3WO6GQ4xoFt/site/?key=statement

#include <bits/stdc++.h>

// #define GARY_DBG
#define GARY_LIB

constexpr int sizik = 200 * 1001;

#define ar std::array

typedef std::vector<std::vector<int>> _kra;

constexpr int INF = 1e9;

struct S {
    int t[27];

    S() { std::fill(t, t + 27, INF); }

    struct Proxy2D {
        int* ptr;
        struct Proxy1D {
            int* ptr;
            int& operator[](int z) { return ptr[z]; }
        };
        Proxy1D operator[](int y) { return Proxy1D{ptr + y * 3}; }
    };

    struct ConstProxy2D {
        const int* ptr;
        struct ConstProxy1D {
            const int* ptr;
            int operator[](int z) const { return ptr[z]; }
        };
        ConstProxy1D operator[](int y) const { return ConstProxy1D{ptr + y * 3}; }
    };

    Proxy2D operator[](int x) { return Proxy2D{t + x * 9}; }

    ConstProxy2D operator[](int x) const { return ConstProxy2D{t + x * 9}; }
};

S dp[sizik];

std::vector<int> kra[sizik];

void merge(S& res, const S& ziutek) {
    S nowy;

    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            for (int z = 0; z < 3; z++) {
                if (res[x][y][z] >= INF) continue;
                for (int a = 0; a < 3; a++) {
                    for (int b = 0; b < 3; b++) {
                        for (int c = 0; c < 3; c++) {
                            if (ziutek[a][b][c] >= INF) continue;

                            int q = std::min(2, x + a);
                            int w = std::max(y, b);
                            int e = std::max(0, std::max(z - a, c - x));

                            nowy[q][w][e] = std::min(nowy[q][w][e], res[x][y][z] + ziutek[a][b][c]);
                        }
                    }
                }
            }
        }
    }

    res = nowy;
}

void par(const S& res, int v) {
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            for (int z = 0; z < 3; z++) {
                if (res[x][y][z] >= INF) continue;
                for (int q = y; q < 3; q++) {
                    int w = 0, e = 0;
                    if (q == 0) {
                        w = z;
                        e = std::max(0, 2 - x);
                    }
                    dp[v][q][w][e] = std::min(dp[v][q][w][e], q + res[x][y][z]);
                }
            }
        }
    }
}

void dfs(int v, int p) {
    S res;
    int c = 0;
    for (const auto& u : kra[v]) {
        if (u == p) continue;
        c++;
        dfs(u, v);
        if (c == 1) {
            res = dp[u];
        } else {
            merge(res, dp[u]);
        }
    }
    if (c == 0) {
        dp[v][0][0][2] = 0;
    } else {
        par(res, v);
    }
}

void solve() {
    int n;
    std::cin >> n;

    if (n == 1) {
        std::cout << "0\n";
        return;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        std::cin >> a >> b;

        kra[a].push_back(b);
        kra[b].push_back(a);
    }

    dfs(1, 1);

    int ans = INF;
    for (int i = 0; i < 3; i++) {
        for (int k = 0; k < 3; k++) {
            ans = std::min(ans, dp[1][i][0][k]);
        }
    }

    std::cout << ans << '\n';
}

int32_t main() {
#ifndef GARY_DBG
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
#endif

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}