#include <bits/stdc++.h>
using namespace std;
long long modexpo(long long x, long long p) {
  long long res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
struct edge {
  long long u, v, w;
  edge(long long a, long long b, long long c) {
    u = a;
    v = b;
    w = c;
  }
};
struct compare {
  bool operator()(const edge a, const edge b) const {
    if (a.u == b.u) {
      if (a.v == b.v) {
        return a.w < b.w;
      }
      return a.v < b.v;
    }
    return a.u < b.u;
  }
};
const long long nax = 100005;
vector<long long> g[nax];
long long tin[nax], tout[nax], table[nax][20], timer = 0;
long long dist[nax], n, u, v;
void dfs(long long x, long long p, long long cnt) {
  dist[x] = cnt;
  table[x][0] = p;
  tin[x] = ++timer;
  for (long long i = 1; i < 20; i++) {
    table[x][i] = table[table[x][i - 1]][i - 1];
  }
  for (long long i : g[x]) {
    if (i != p) {
      dfs(i, x, cnt + 1);
    }
  }
  tout[x] = ++timer;
}
bool anc(long long x, long long y) {
  return tin[x] <= tin[y] && tout[x] >= tout[y];
}
long long lca(long long x, long long y) {
  if (anc(x, y)) {
    return x;
  }
  if (anc(y, x)) {
    return y;
  }
  for (long long i = 19; i >= 0; i--) {
    if (!anc(table[x][i], y)) {
      x = table[x][i];
    }
  }
  return table[x][0];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> u >> v;
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(v, v, 0);
  long long mx = 0;
  if (g[u].size() == 1 && dist[g[u][0]] == 1) {
    mx = 1;
  }
  for (long long i = 1; i <= n; i++) {
    if (i == u) {
      continue;
    }
    long long l = lca(i, u);
    if (l == v) {
      continue;
    }
    long long cur = dist[u] + dist[i] - 2 * dist[l];
    if (cur < dist[i]) {
      mx = max(mx, dist[i] - 1);
    }
  }
  cout << mx << "\n";
}
