func_code_string: #include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   vector<pair<int, int> > g[3005];   pair<int, int> es[3005];   int dfs(int v, int p) {     int res = 0;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res += e.second + dfs(e.first, v);     }     return res;   }   int move(int v, int p, int val) {     int res = val;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res = min(res, move(e.first, v, val + 1 - e.second * 2));     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(make_pair(b, 0));       g[b].push_back(make_pair(a, 1));       es[i] = make_pair(a, b);     }     int ans = INF;     if (n <= 2) ans = 0;     for (int i = 0; i < n - 1; ++i) {       int A, B;       A = es[i].first;       B = es[i].second;       int sum1 = dfs(A, B), sum2 = dfs(B, A);       ans = min(ans, move(A, B, sum1) + move(B, A, sum2));     }     cout << ans << endl;     return 0;   }   