#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
int n, u, v, a, b;
bool flag;
vector<int> g[100001];
int result(int x, int fx, int y) {
  int res = 0;
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] == fx) continue;
    if (g[x][i] == y) {
      flag = true;
      return 0;
    }
    res = max(res, result(g[x][i], x, y));
  }
  return res + 1;
}
bool r2(int x, int y, int fy) {
  bool res = false;
  for (int i = 0; i < g[y].size(); i++) {
    if (g[y][i] == fy) continue;
    if (g[y][i] == x) return true;
    if (r2(x, g[y][i], y)) {
      res = true;
      break;
    }
  }
  return res;
}
void dfs(int x, int y, int fx, int fy, int step, int c, bool f) {
  if (c) {
    if (g[x].size() == 1) {
      if (g[x][0] == y) {
        cout << step;
        exit(0);
      }
      dfs(g[x][0], y, x, fy, step, c ^ 1, 1);
    } else {
      int m = 0, mi = -1;
      for (int i = 0; i < g[x].size(); i++) {
        if (!f) {
          if (g[x][i] == fx) continue;
        }
        flag = false;
        if (g[x][i] == y) continue;
        int mm = result(g[x][i], x, y);
        if (flag) continue;
        if (mm > m) {
          m = mm;
          mi = i;
        }
      }
      dfs(g[x][mi], y, x, fy, step, c ^ 1, 0);
    }
  } else {
    for (int i = 0; i < g[y].size(); i++) {
      int yy = g[y][i];
      if (yy == x) {
        cout << step + 1;
        exit(0);
      }
      if (r2(x, yy, y)) dfs(x, yy, fx, y, step + 1, c ^ 1, f);
    }
  }
}
int main() {
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  u--, v--;
  dfs(u, v, -1, -1, 0, 1, 0);
  return 0;
}
