#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> G(100001);
long long dis[100001];
long long depth[100001];
bool visited[100001];
bool reachable[100001];
long long f(long long x) {
  if (x % 2) {
    return max(0LL, x - 2);
  } else {
    return max(0LL, x - 1);
  }
}
void dfs1(long long st, long long d) {
  visited[st] = 1;
  dis[st] = d;
  for (auto i : G[st]) {
    if (!visited[i]) {
      dfs1(i, d + 1);
    }
  }
}
void dfs2(long long st, long long d) {
  visited[st] = 1;
  depth[st] = d;
  for (auto i : G[st]) {
    if (!visited[i]) {
      dfs2(i, d + 1);
    }
  }
}
int32_t main() {
  long long n, a, b;
  cin >> n >> a >> b;
  for (long long i = 0; i < n - 1; i++) {
    long long v1, v2;
    cin >> v1 >> v2;
    G[v1].push_back(v2);
    G[v2].push_back(v1);
  }
  dfs1(a, 0);
  fill(visited, visited + n + 1, 0);
  dfs2(b, 0);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (dis[i] + 1 < depth[i]) {
      ans = max(ans, dis[i] + f(depth[i] - dis[i]));
    }
  }
  cout << ans << endl;
}
