#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>> &tree, vector<int> &res, vector<int> &vis, int fir,
         int depth) {
  res[fir] = depth;
  for (int i = 0; i < (int)tree[fir].size(); i++) {
    if (vis[tree[fir][i]] == 0) {
      vis[tree[fir][i]] = 1;
      dfs(tree, res, vis, tree[fir][i], depth + 1);
    }
  }
}
int lastdfs(vector<vector<int>> &tree, vector<int> &fi, vector<int> &se,
            vector<int> &vis, int fir) {
  int maxx = (fi[fir] - se[fir]) % 2 == 0 ? fi[fir] : fi[fir] - 1;
  bool flag = false;
  for (int i = 0; i < (int)tree[fir].size(); i++) {
    if (fi[tree[fir][i]] > se[tree[fir][i]]) {
      flag = true;
      break;
    }
  }
  if (!flag) {
    return maxx - 1;
  }
  for (int i = 0; i < (int)tree[fir].size(); i++) {
    if (vis[tree[fir][i]] == 0 && fi[tree[fir][i]] > se[tree[fir][i]]) {
      vis[tree[fir][i]] = 1;
      maxx = max(maxx, lastdfs(tree, fi, se, vis, tree[fir][i]));
    }
  }
  return maxx;
}
int main() {
  int n, v, u;
  scanf("%d%d%d", &n, &u, &v);
  u--;
  v--;
  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    tree[x - 1].push_back(y - 1);
    tree[y - 1].push_back(x - 1);
  }
  vector<int> fir(n), sec(n);
  vector<int> vis(n);
  vis[v] = 1;
  dfs(tree, fir, vis, v, 0);
  for (int i = 0; i < n; i++) vis[i] = 0;
  vis[u] = 1;
  dfs(tree, sec, vis, u, 0);
  for (int i = 0; i < n; i++) vis[i] = 0;
  vis[u] = 1;
  printf("%d\n", max(0, lastdfs(tree, fir, sec, vis, u)));
  return 0;
}
