#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int64_t mod1 = 1e9 + 6;
int64_t power(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
  else
    return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
           mod;
}
int64_t n, x, y;
vector<int64_t> v[200001];
int64_t dis[200001];
int64_t dis1[200001];
void dfs(int64_t u, int64_t par) {
  dis[u] = dis[par] + 1;
  for (int64_t i = 0; i < v[u].size(); ++i) {
    if (v[u][i] != par) {
      dfs(v[u][i], u);
    }
  }
}
void dfs1(int64_t u, int64_t par) {
  dis1[u] = dis1[par] + 1;
  for (int64_t i = 0; i < v[u].size(); ++i) {
    if (v[u][i] != par) {
      dfs1(v[u][i], u);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> x >> y;
  for (int64_t i = 1; i <= n - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  memset(dis, 0, sizeof(dis));
  dfs(y, 0);
  int64_t maxi = 0;
  for (int64_t i = 1; i <= n; ++i) {
    maxi = max(maxi, dis[i]);
  }
  vector<int64_t> te;
  for (int64_t i = 1; i <= n; ++i) {
    if (dis[i] == maxi) {
      te.push_back(i);
    }
  }
  memset(dis1, 0, sizeof(dis1));
  dfs1(x, 0);
  int64_t mini = 1e9;
  for (int64_t i = 0; i < te.size(); ++i) {
    mini = min(dis1[te[i]], mini);
  }
  if (mini > maxi) {
    cout << (dis[y] - 1);
    return 0;
  } else {
    int64_t te = maxi - mini;
    cout << maxi - 2 << '\n';
  }
}
