#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 100005;
const long long mm = 1e+18;
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long ncr(long long n, long long k) {
  long long C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = min(i, k); j > 0; j--) C[j] = (C[j] + C[j - 1]) % mod;
  }
  return C[k];
}
vector<int> gr[maxn];
int vis[maxn];
int distt[maxn];
int par[maxn];
void bfs(int he) {
  queue<int> q;
  q.push(he);
  distt[he] = 0;
  vis[he] = 0;
  while (q.size()) {
    int tt = q.front();
    q.pop();
    for (auto x : gr[tt]) {
      if (vis[x]) {
        par[x] = tt;
        q.push(x);
        vis[x] = 0;
        distt[x] = distt[tt] + 1;
      }
    }
  }
}
void bfs2(int he, int wh) {
  queue<int> q;
  q.push(he);
  vis[he] = 0;
  while (q.size()) {
    int tt = q.front();
    q.pop();
    for (auto x : gr[tt]) {
      if (vis[x] && x != wh) {
        q.push(x);
        vis[x] = 0;
      }
    }
  }
}
void dfs(int he, int di) {
  distt[he] = di;
  vis[he] = 0;
  for (auto x : gr[he]) {
    if (vis[x]) dfs(x, di + 1);
  }
}
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  int u1 = u;
  for (int i = 0; i < n + 2; i++) vis[i] = 1;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  bfs(v);
  int x = distt[u];
  x /= 2;
  int mx = distt[par[u]];
  if (distt[u] % 2 == 0) x--;
  while (x--) {
    u = par[u];
  }
  for (int i = 0; i < n + 3; i++) {
    vis[i] = 1;
    distt[i] = 0;
  }
  bfs2(v, u);
  vector<int> vv;
  for (int i = 1; i <= n; i++) {
    if (vis[i] && gr[i].size() == 1) {
      vv.push_back(i);
    }
  }
  for (int i = 0; i < n + 2; i++) vis[i] = 1;
  dfs(u1, 0);
  for (auto x : vv) {
    mx = max(mx, distt[x]);
  }
  cout << mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
