#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int n, s, t, ans, bl;
vector<int> v[100005], path;
bool dfs(int x, int fa) {
  path.push_back(x);
  if (x == t) return 1;
  for (int(i) = (0); (i) < (v[x].size()); (i)++) {
    int to = v[x][i];
    if (to != fa) {
      if (dfs(to, x)) return 1;
    }
  }
  path.pop_back();
  return 0;
}
int run(int x, int fa) {
  int ret = 0;
  for (int(i) = (0); (i) < (v[x].size()); (i)++) {
    int to = v[x][i];
    if (to == bl || to == fa) continue;
    ret = max(ret, run(to, x) + 1);
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &s, &t);
  for (int(i) = (1); (i) < (n); (i)++) {
    int t1, t2;
    scanf("%d%d", &t1, &t2);
    v[t1].push_back(t2);
    v[t2].push_back(t1);
  }
  dfs(s, 0);
  int len = path.size();
  int ans = 0;
  bool flg = 1;
  for (int(i) = (0); (i) < (v[s].size()); (i)++)
    if (v[s][i] != t) flg = 0;
  for (int(i) = (0); (i) < (path.size()); (i)++) {
    int x = path[i];
    if (i) bl = path[i - 1];
    int p = (i + 1 == len ? 0 : path[i + 1]);
    ans = max(ans, run(path[i], p) + len - i - 1);
  }
  printf("%d\n", flg ? 0 : ans - 1);
  return 0;
}
