#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const unsigned long long BASE = 19260817;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
const double PI = acos(-1);
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline T readT() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
  return res * f;
}
namespace Comb {
inline void exgcd(long long a, long long b, long long &g, long long &x,
                  long long &y) {
  if (!b)
    g = a, x = 1, y = 0;
  else
    exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
inline long long inv(long long a) {
  long long g, res, tmp;
  exgcd(a, MOD, g, res, tmp);
  return ((res % MOD) + MOD) % MOD;
}
long long f[N], invFact[N];
inline void prepare() {
  f[0] = 1;
  int n = 200000;
  for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
  invFact[n] = inv(f[n]);
  for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
inline long long C(int n, int m) {
  if (!m) return 1;
  if (n == m) return 1;
  if (m > n) return 0;
  if (m < 0) return 0;
  return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}  // namespace Comb
int n, ans, a, b, dis[N];
bool flag;
std::vector<int> g[N];
void dfs(int x, int fa, int dep) {
  if (!flag)
    dis[x] = dep;
  else if (dep >= dis[x])
    return (void)(ans = std::max(ans, dep));
  for (auto to : g[x]) {
    if (to == fa) continue;
    dfs(to, x, dep + 1);
  }
  if (g[x].size() == 1) ans = std::max(ans, dis[x] - 1);
}
int main() {
  cin >> n >> a >> b;
  if (a == b) return puts("0"), 0;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(b, -1, 0);
  flag = true;
  dfs(a, -1, 0);
  printf("%d\n", ans);
  return 0;
}
