#include <bits/stdc++.h>
using namespace std;
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0, -1};
const int dy4[6] = {1, 0, -1, 0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(long long &x, long long v) {
  if (x == -1)
    x = v;
  else if (x > v)
    x = v;
}
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
void extgcd(long long a, long long b, long long &d, long long &x,
            long long &y) {
  if (!b) {
    d = a;
    x = 1;
  } else {
    extgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long inverse(long long a, long long n) {
  long long d, x, y;
  extgcd(a, n, d, x, y);
  return d == 1 ? (x + n) % n : -1;
}
const int maxn = 2e5 + 15;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
int n, st1, st2;
std::vector<int> edge[maxn];
int dep[maxn];
void dfs(int x, int fa, int root) {
  if (x != root) {
    dep[x] = dep[fa] + 1;
  }
  for (int i = 0; i < edge[x].size(); i++) {
    int nxt = edge[x][i];
    if (nxt == fa) {
      continue;
    }
    dfs(nxt, x, root);
  }
}
int dep1[maxn], dep2[maxn];
void solve() {
  scanf("%d", &(n));
  scanf("%d", &(st1));
  scanf("%d", &(st2));
  for (int i = 1; i <= n - 1; i++) {
    int x;
    int y;
    scanf("%d", &(x));
    scanf("%d", &(y));
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  memset(dep, 0, sizeof(dep));
  dfs(st2, -1, st2);
  int ans = dep[st1] - 1;
  int maxx = 0;
  for (int i = 1; i <= n; i++) {
    dep1[i] = dep[i];
    maxx = max(maxx, dep1[i]);
  }
  memset(dep, 0, sizeof(dep));
  dfs(st1, -1, st1);
  for (int i = 1; i <= n; i++) {
    dep2[i] = dep[i];
  }
  for (int i = 1; i <= n; i++) {
    if (dep1[i] == maxx) {
      if (dep2[i] < dep1[i]) {
        ans = max(ans, dep1[i] - 1);
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
