#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using ll = long long;
using prique = priority_queue<long long>;
const ll INF = LLONG_MAX / 3;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct UnionFind {
  vector<long long> par;
  vector<long long> rank;
  vector<long long> sizeuf;
  UnionFind(long long n = 1) { init(n); }
  void init(long long n = 1) {
    par.resize(n);
    rank.resize(n);
    sizeuf.resize(n);
    for (long long i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
      sizeuf[i] = 1;
    }
  }
  long long root(long long x) {
    if (par[x] == x) {
      return x;
    } else {
      long long r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    sizeuf[x] += sizeuf[y];
    return true;
  }
  long long size(long long x) { return sizeuf[root(x)]; }
};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); }
const long long MOD = 1234567;
long long ra[110000];
vector<long long> es[110000];
vector<long long> memo;
void bfs(long long s) {
  ra[s] = 1;
  queue<P> task;
  for (long long i = (long long)0, i_len = (es[s].size()); i < i_len; i++)
    task.push(P(s, es[s][i]));
  while (!task.empty()) {
    P t = task.front();
    task.pop();
    ra[t.second] = ra[t.first] + 1;
    long long c = 0;
    for (long long i = (long long)0, i_len = (es[t.second].size()); i < i_len;
         i++) {
      c++;
      if (ra[es[t.second][i]] == -1) task.push(P(t.second, es[t.second][i]));
    }
    if (c == 1) memo.push_back(t.second);
  }
}
long long md[110000];
void dfs(long long s, long long d) {
  md[s] = d;
  for (long long i = (long long)0, i_len = (es[s].size()); i < i_len; i++) {
    if (md[es[s][i]] < d && ra[es[s][i]] < ra[s]) dfs(es[s][i], d);
  }
}
long long solve(long long sa) { return sa - 1; }
signed main() {
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (long long i = (long long)0, i_len = (n - 1); i < i_len; i++) {
    long long a, b;
    cin >> a >> b;
    es[a - 1].push_back(b - 1);
    es[b - 1].push_back(a - 1);
  }
  for (long long i = (long long)0, i_len = (n); i < i_len; i++) ra[i] = -1;
  bfs(v);
  for (long long i = (long long)0, i_len = (n); i < i_len; i++) md[i] = -1;
  for (long long i = (long long)0, i_len = (memo.size()); i < i_len; i++)
    dfs(memo[i], ra[memo[i]]);
  long long ans = 0;
  chmax(ans, md[u] - ra[u] + solve(ra[u] - 1));
  long long a, t;
  a = 1;
  for (long long i = (long long)0, i_len = (es[u].size()); i < i_len; i++)
    if (ra[es[u][i]] < ra[u]) t = es[u][i];
  while (t - a >= 1) {
    chmax(ans, a - v + md[t] - ra[t] + solve(t - a));
    a++;
    for (long long i = (long long)0, i_len = (es[t].size()); i < i_len; i++)
      if (ra[es[t][i]] < ra[t]) {
        t = es[t][i];
        break;
      }
  }
  cout << ans << endl;
}
