func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 3010;   bool visit[maxn];   int n, m, ans, f[maxn];   vector<int> ve;   vector<pair<int, int> > maps[maxn];   void first_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         first_dfs(v);         f[u] += f[v] + w;       }     }   }   void second_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         f[v] = f[u] + (w ? -1 : 1);         m = min(m, f[v]);         second_dfs(v);       }     }   }   void solve(const int u) {     first_dfs(u);     ans = min(ans, f[u]);     if (((int)(maps[u]).size()) >= 2) {       ve.clear();       memset(visit, 0, sizeof(visit));       visit[u] = 1;       for (int i = 0; i < ((int)(maps[u]).size()); ++i) {         int v = maps[u][i].first;         int w = maps[u][i].second;         m = f[v];         second_dfs(v);         ve.push_back(m + (w ? -1 : 1) - f[v]);       }       sort(ve.begin(), ve.end());       ans = min(ans, f[u] + ve[0] + ve[1]);     }   }   int main() {     scanf( %d , &n);     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       maps[u].push_back(make_pair(v, 0));       maps[v].push_back(make_pair(u, 1));     }     ans = maxn;     for (int i = 1; i <= n; ++i) {       memset(f, 0, sizeof(f));       memset(visit, 0, sizeof(visit));       solve(i);     }     printf( %d n , ans);     return 0;   }   