#include <bits/stdc++.h>
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
vector<int> edge[100010];
bool used[100010];
int route[100010];
int dist[100010];
int dfs(int from, int par, int goal) {
  if (from == goal) {
    route[from] = 1;
    return 1;
  }
  used[from] = true;
  int ret = 0;
  for (int to : edge[from]) {
    if (to == par) {
      continue;
    }
    if (not used[to]) {
      int tmp = dfs(to, from, goal);
      ret += tmp;
    }
  }
  if (ret > 0) {
    route[from] = ret + 1;
    return ret + 1;
  }
  return ret;
}
int dfs1(int from, int par) {
  int ret = 0;
  used[from] = true;
  for (int to : edge[from]) {
    if (route[to] != -1) continue;
    if (not used[to]) ret = max(ret, dfs1(to, from));
  }
  return ret + 1;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) route[i] = -1;
  int u, v;
  cin >> u >> v;
  --u, --v;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs(v, -1, u);
  for (int i = 0; i < n; ++i) used[i] = false;
  int maxi = 0;
  for (int i = 0; i < n; ++i) {
    if (route[i] != -1) dist[i] = dfs1(i, -1);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (route[i] != -1) {
      if (i == u) {
        int ud = dist[i] - 1;
        int vd = route[v] - route[u];
        ans = max(ans, ud + vd);
        continue;
      }
      int uu = route[i] - route[u];
      int vv = route[v] - route[i];
      if (uu < vv) {
        int ud = dist[i] - 1;
        int vd = vv - uu;
        if ((ud + vd) % 2 == 0) {
          ans = max(ans, ud + vd - 1);
        } else {
          ans = max(ans, ud + vd);
        }
      } else {
        if (route[v] % 2 == 0) {
          ans = max(ans, route[v] - 2);
        } else {
          ans = max(ans, route[v] - 2);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
