#include <bits/stdc++.h>
using namespace std;
class Comb {
 private:
  long long *fac, *finv, *inv;

 public:
  Comb() {
    fac = new long long[1000000];
    finv = new long long[1000000];
    inv = new long long[1000000];
    fac[0] = 1;
    for (int i = 1; i < 1000000; i++) {
      fac[i] = i * fac[i - 1];
      fac[i] %= 1000000007;
    }
    inv[1] = 1;
    for (int i = 2; i < 1000000; i++) {
      inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    }
    finv[0] = 1;
    for (int i = 1; i < 1000000; i++) {
      finv[i] = inv[i] * finv[i - 1];
      finv[i] %= 1000000007;
    }
  }
  long long calc(long long n, long long k) {
    long long c = fac[n];
    c *= finv[k];
    c %= 1000000007;
    c *= finv[n - k];
    c %= 1000000007;
    return c;
  }
};
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> graph[n];
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int d_from_u[n];
  vector<int> path[n];
  path[u] = {u};
  for (int i = 0; i < n; i++) {
    d_from_u[i] = 1000000;
  }
  d_from_u[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < graph[now].size(); i++) {
      if (d_from_u[graph[now][i]] != 1000000) continue;
      d_from_u[graph[now][i]] = d_from_u[now] + 1;
      path[graph[now][i]] = path[now];
      path[graph[now][i]].push_back(now);
      q.push(graph[now][i]);
    }
  }
  int d_from_v[n];
  for (int i = 0; i < n; i++) {
    d_from_v[i] = 1000000;
  }
  d_from_v[v] = 0;
  q.push(v);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < graph[now].size(); i++) {
      if (d_from_v[graph[now][i]] != 1000000) continue;
      d_from_v[graph[now][i]] = d_from_v[now] + 1;
      q.push(graph[now][i]);
    }
  }
  int ans = 0;
  ans += d_from_u[v] - 1;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (d_from_v[i] == d_from_u[i] + d_from_u[v]) {
      count = max(count, d_from_u[i]);
    }
  }
  ans += count;
  int esc = 0;
  int d[n];
  for (int i = 0; i < n; i++) {
    d[i] = 1000000;
  }
  for (int i = 0; i < path[v].size(); i++) {
    d[path[v][i]] = 0;
  }
  for (int i = 1; i < path[v].size() - 1; i++) {
    esc = -1;
    int temp = path[v][i];
    if (d_from_u[temp] >= d_from_v[temp]) continue;
    q.push(temp);
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      esc = max(esc, d[now]);
      for (int j = 0; j < graph[now].size(); j++) {
        if (d[graph[now][j]] != 1000000) continue;
        d[graph[now][j]] = d[now] + 1;
        q.push(graph[now][j]);
      }
    }
    int temp_ans = d_from_v[temp] - 1 + esc;
    ans = max(temp_ans, ans);
  }
  cout << ans << endl;
  return 0;
}
