#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)(1e9 + 7);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct RMinQ {
 private:
  int N;
  vector<long long> node, lazy;
  vector<bool> lazyFlg;
  long long DEFAULT;

 public:
  void init(int n, long long def = 9223372036854775807LL) {
    DEFAULT = def;
    node.clear();
    lazy.clear();
    lazyFlg.clear();
    N = 1;
    while (N < n) N = (N << 1);
    for (int i = 0; i < 2 * N - 1; i++) {
      node.push_back(DEFAULT);
      lazy.push_back(0LL);
      lazyFlg.push_back(false);
    }
  }
  void eval(int k, int l, int r) {
    if (lazyFlg[k]) {
      node[k] = lazy[k];
      if (r - l > 1) {
        lazy[(k << 1) + 1] = lazy[k];
        lazyFlg[(k << 1) + 1] = true;
        lazy[(k << 1) + 2] = lazy[k];
        lazyFlg[(k << 1) + 2] = true;
      }
      lazy[k] = 0LL;
      lazyFlg[k] = false;
    } else {
      node[k] += lazy[k];
      if (r - l > 1) {
        lazy[(k << 1) + 1] += lazy[k];
        lazy[(k << 1) + 2] += lazy[k];
      }
      lazy[k] = 0LL;
    }
  }
  void update(int a, long long x) { update(a, a + 1, x); }
  void update(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = N;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = x;
      lazyFlg[k] = true;
      eval(k, l, r);
    } else {
      update(a, b, x, (k << 1) + 1, l, (l + r) >> 1);
      update(a, b, x, (k << 1) + 2, (l + r) >> 1, r);
      node[k] = std::min(node[(k << 1) + 1], node[(k << 1) + 2]);
    }
  }
  void add(int a, long long x) { add(a, a + 1, x); }
  void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = N;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += x;
      eval(k, l, r);
    } else {
      add(a, b, x, (k << 1) + 1, l, (l + r) >> 1);
      add(a, b, x, (k << 1) + 2, (l + r) >> 1, r);
      node[k] = std::min(node[(k << 1) + 1], node[(k << 1) + 2]);
    }
  }
  long long min(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = N;
    if (b <= l || r <= a) return 9223372036854775807LL;
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    return std::min(min(a, b, (k << 1) + 1, l, (l + r) >> 1),
                    min(a, b, (k << 1) + 2, (l + r) >> 1, r));
  }
  long long m;
  int find(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) {
      m = min(a, b);
      r = N;
    }
    if (r <= a || b <= l) return INT_MAX;
    if (r - l == 1) {
      if (node[k] == m)
        return l;
      else
        return INT_MAX;
    }
    if (a <= l && r <= b) {
      int valueL = min(a, b, (k << 1) + 1, l, (l + r) / 2);
      int valueR = min(a, b, (k << 1) + 2, (l + r) / 2, r);
      if (valueL == m) return find(a, b, (k << 1) + 1, l, (l + r) >> 1);
      if (valueR == m) return find(a, b, (k << 1) + 2, (l + r) >> 1, r);
      return INT_MAX;
    }
    return std::min(find(a, b, (k << 1) + 1, l, (l + r) >> 1),
                    find(a, b, (k << 1) + 2, (l + r) >> 1, r));
  }
};
int N, u, v;
vector<int> e[100000];
int pre[100000];
int r[100000];
int depth[100000];
int cnt = 0;
vector<int> EulerTour;
int pos[100000];
void dfs(int n, int p, int d) {
  pre[n] = cnt;
  r[cnt] = n;
  cnt++;
  depth[n] = d;
  EulerTour.push_back(n);
  for (int(i) = 0; (i) < (int)(e[n].size()); (i)++) {
    if (e[n][i] == p) continue;
    dfs(e[n][i], n, d + 1);
    EulerTour.push_back(n);
  }
  pos[n] = EulerTour.size() - 1;
}
RMinQ rmq;
int lca(int a, int b) {
  int x = pos[a];
  int y = pos[b];
  if (x > y) swap(x, y);
  return r[rmq.min(x, y + 1)];
}
int dist(int a, int b) { return depth[a] + depth[b] - 2 * depth[lca(a, b)]; }
signed main() {
  cin >> N >> u >> v;
  u--;
  v--;
  for (int(i) = 0; (i) < (int)(N - 1); (i)++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    e[A].push_back(B);
    e[B].push_back(A);
  }
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    if (e[i].size() > 1) {
      dfs(i, -1, 0);
      break;
    }
  }
  rmq.init(EulerTour.size());
  for (int(i) = 0; (i) < (int)(EulerTour.size()); (i)++)
    rmq.update(i, EulerTour[i]);
  int ans = 0;
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    if (e[i].size() == 1) {
      int x = dist(i, u);
      int y = dist(i, v);
      if (x >= y) continue;
      if ((x + y) % 2 == 0)
        ans = max(ans, dist(i, v) - 1);
      else
        ans = max(ans, dist(i, v) - 1);
    }
  }
  cout << ans << endl;
}
