func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 3000 + 10;   int sum, d[maxn], dp[maxn][2];   vector<pair<int, int> > edge[maxn];   int min(int a, int b) { return a < b ? a : b; }   void dfs(int u, int f, int w) {     if (f == -1) {       sum = 0;       d[u] = 0;       dp[u][0] = dp[u][1] = 0;     } else {       dp[u][1] = dp[f][1] + w;       dp[u][0] = min(dp[f][0], dp[f][1]) + !w;       d[u] = d[f] + w;     }     for (vector<pair<int, int> >::iterator it = edge[u].begin();          it != edge[u].end(); it++) {       int to = it->first;       int wt = it->second;       if (to == f) continue;       sum += wt;       dfs(to, u, wt);     }   }   int main() {     int n, u, v, ret = maxn;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       edge[u].push_back(make_pair(v, 0));       edge[v].push_back(make_pair(u, 1));     }     for (int i = 1; i <= n; i++) {       dfs(i, -1, 0);       for (int j = 1; j <= n; j++) {         ret = min(ret, sum + min(dp[j][0], dp[j][1]) - d[j]);       }     }     cout << ret << endl;     return 0;   }   