#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
class edge {
 public:
  int t, nxt;
  edge(int _t, int _nxt) {
    t = _t;
    nxt = _nxt;
  }
};
vector<edge> edges;
int e = 0;
int *d;
int n;
int *h, *mh;
int *f;
void add_edge(int s, int t) {
  edges.push_back(edge(t, d[s]));
  d[s] = e++;
}
void dfs(int x) {
  mh[x] = 0;
  for (int p = d[x]; p != -1; p = edges[p].nxt) {
    int t = edges[p].t;
    if (h[t] == -1) {
      h[t] = h[x] + 1;
      f[t] = x;
      dfs(t);
      mh[x] = max(mh[x], mh[t] + 1);
    }
  }
}
int get_ans(int d, int emp) {
  if (d <= 0) {
    return 0;
  }
  return emp + d - 1;
}
int main() {
  int n, a, b, s, t;
  cin >> n >> a >> b;
  --a;
  --b;
  swap(a, b);
  d = new int[n];
  f = new int[n];
  for (int i = 0; i < n; ++i) {
    d[i] = -1;
  }
  for (int i = 0; i < n - 1; ++i) {
    cin >> s >> t;
    --s;
    --t;
    add_edge(s, t);
    add_edge(t, s);
  }
  h = new int[n];
  mh = new int[n];
  for (int i = 0; i < n; ++i) {
    h[i] = -1;
    mh[i] = -1;
    f[i] = -1;
  }
  h[a] = 0;
  dfs(a);
  int d = h[b], emp = mh[b];
  int ans = 0;
  int c = 0;
  for (int i = b; i != -1; i = f[i]) {
    ans = max(ans, get_ans(d - 2 * c, mh[i]) + c);
    if (d - 2 * c <= 0) {
      break;
    }
    ++c;
  }
  cout << ans << endl;
  return 0;
}
