#include <bits/stdc++.h>   using namespace std;   const int N = 3010;   struct edge {     int v, next, flag;   } e[N << 2];   int head[N], cnt;   void addedge(int u, int v, int flag) {     e[cnt].v = v;     e[cnt].flag = flag;     e[cnt].next = head[u];     head[u] = cnt++;   }   int sum[N], dp[N];   void dfs(int u, int pre) {     sum[u] = 0;     for (int i = head[u]; i != -1; i = e[i].next) {       if (e[i].v == pre) continue;       dfs(e[i].v, u);       int v = e[i].v;       sum[u] += sum[v] + e[i].flag;     }     dp[u] = sum[u];     for (int i = head[u]; i != -1; i = e[i].next) {       if (e[i].v == pre) continue;       int v = e[i].v;       dp[u] = min(dp[u], sum[u] - sum[v] + 1 - e[i].flag + dp[v] - e[i].flag);     }   }   int main() {     memset(head, -1, sizeof(head));     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y, z;       scanf( %d%d , &x, &y);       addedge(x, y, 0);       addedge(y, x, 1);     }     int ans = 0x7fffffff;     for (int i = 1; i <= n; i++) {       dfs(i, -1);       for (int j = 1; j <= n; j++) {         ans = min(ans, sum[i] - sum[j] + dp[j]);       }     }     printf( %d n , ans);     return 0;   }   