#include <bits/stdc++.h>
using namespace std;
long long pw(long long x, long long a) {
  if (a == 0) return 1;
  long long t = pw(x, a / 2);
  if (a % 2 == 0)
    return (t * t);
  else
    return (t * t * x);
}
bool prime(int x) {
  if (x < 2) return false;
  for (int i = 2; i <= sqrt(x); i++) {
    if ((x % i) == 0) return false;
  }
  return true;
}
vector<int> a[100100];
vector<int> dis(100010, -1);
queue<pair<int, int> > go;
void bfs1(int i, int x) {
  dis[i] = x;
  for (int j = 0; j < a[i].size(); j++) {
    if (dis[a[i][j]] == -1) {
      go.push({a[i][j], x + 1});
      dis[a[i][j]] = x + 1;
    }
  }
  go.pop();
}
int ans = 0;
bool vis[100010];
void bfs2(int i, int x) {
  if (dis[i] <= x && x != 0) {
    int cur = x;
    if (x > dis[i]) cur--;
    ans = max(ans, cur);
    vis[i] = 1;
    for (int j = 0; j < a[i].size(); j++) {
      if (!vis[a[i][j]] && dis[a[i][j]] < x + 1) {
        go.push({a[i][j], x + 1});
        vis[a[i][j]] = 1;
      }
    }
  } else {
    vis[i] = 1;
    for (int j = 0; j < a[i].size(); j++) {
      if (!vis[a[i][j]]) {
        go.push({a[i][j], x + 1});
        vis[a[i][j]] = 1;
      }
    }
  }
  go.pop();
  if (go.empty()) {
    int cur = x;
    if (x > dis[i]) cur--;
    ans = max(ans, cur);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, u, v;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  go.push({u, 0});
  dis[u] = 0;
  while (!go.empty()) {
    bfs1(go.front().first, go.front().second);
  }
  go.push({v, 0});
  while (!go.empty()) bfs2(go.front().first, go.front().second);
  cout << ans << endl;
  return 0;
}
