func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   const int N = 3000 + 5;   int n, x, y, all, up[N], down[N], w[N];   vector<pair<int, int> > v[N];   void dfs(int root, int x, int w, int up, int down) {     ::up[x] = up;     ::down[x] = down;     ::w[x] = w;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++)       if (it->first != root) {         all += it->second;         dfs(x, it->first, w, up + it->second, down + !it->second);       }   }   int solve(int x) {     all = 0;     w[x] = 0;     up[x] = 0;     down[x] = 0;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++) {       all += it->second;       dfs(x, it->first, it->first, it->second, !it->second);     }     int ans = all, mni = -1;     for (int i = 1; i <= n; i++) {       if (all - up[i] + down[i] < ans) {         ans = all - up[i] + down[i];         mni = w[i];       }     }     int ans2 = ans;     for (int i = 1; i <= n; i++) {       if (w[i] != mni and ans - up[i] + down[i] < ans2) {         ans2 = ans - up[i] + down[i];       }     }     return ans2;   }   int main() {     ios ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y;       v[x].push_back(make_pair(y, 0));       v[y].push_back(make_pair(x, 1));     }     int ans = inf;     for (int i = 1; i <= n; i++) ans = min(ans, solve(i));     cout << ans <<   n ;     return 0;   }   