#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a, b;
vector<int> adj[N];
int dsa[N];
int dsb[N];
void dfs1(int x, int p) {
  for (auto y : adj[x]) {
    if (y != p) {
      dsa[y] = dsa[x] + 1;
      dfs1(y, x);
    }
  }
}
void dfs2(int x, int p) {
  for (auto y : adj[x]) {
    if (y != p) {
      dsb[y] = dsb[x] + 1;
      if (dsb[y] == dsa[y]) continue;
      dfs2(y, x);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(a, a);
  dfs2(b, b);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dsb[i] >= dsa[i]) {
      if (dsb[i] % 2 == dsa[i] % 2) {
        ans = max(ans, dsb[i]);
      } else {
        ans = max(ans, dsb[i] - 1);
      }
    }
  }
  cout << ans;
  return 0;
}
