#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 dist[2][nax], n, u, v;
void dfs(long long x, long long p, long long cnt, long long type) {
  dist[type][x] = cnt;
  for (long long i : g[x]) {
    if (i == p) {
      continue;
    }
    dfs(i, x, cnt + 1, type);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> u >> v;
  long long mx = 0;
  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(u, u, 0, 0);
  dfs(v, v, 0, 1);
  if (g[u].size() == 1 && dist[1][g[u][0]] == 1) {
    mx = 1;
  }
  for (long long i = 1; i <= n; i++) {
    if (dist[0][i] < dist[1][i]) {
      mx = max(mx, dist[0][i]);
    }
  }
  cout << mx << "\n";
}
