#include <bits/stdc++.h>
using namespace std;
int n, x, y, st, timer, Size[100005], tin[100005], tout[100005], H[100005];
vector<int> g[100005], used;
void DFS(int v, int p, int h) {
  used[v] = 1;
  tin[v] = timer++;
  H[v] = h;
  for (int k = 0; k < g[v].size(); k++) {
    int to = g[v][k];
    if (used[to] == 0) DFS(to, v, h + 1);
  }
  tout[v] = timer++;
  Size[p] += Size[v];
}
bool yes(int a, int b) {
  if (tin[a] <= tin[b] && tout[a] >= tout[b]) return true;
  return false;
}
int fin = 0, ind = 0;
void DFS2(int v) {
  used[v] = 1;
  if (v == st) ind = 1;
  int to = 0;
  for (int k = 0; k < g[v].size(); k++) {
    if (ind && used[g[v][k]] == 0 && Size[to] < Size[g[v][k]]) to = g[v][k];
    if (ind == 0) {
      if (used[g[v][k]] == 0 && yes(g[v][k], st)) to = g[v][k];
    }
  }
  if (to == 0)
    fin = v;
  else
    DFS2(to);
}
int main() {
  cin >> n >> x >> y;
  Size[n] = 1;
  for (int k = 1; k < n; k++) {
    Size[k] = 1;
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  used.resize(0);
  used.resize(n + 1, 0);
  DFS(y, 0, 0);
  H[0] = INT_MAX;
  for (int k = 1; k <= n; k++) {
    if (yes(k, x) && H[k] > H[x] - H[k]) {
      if (H[st] > H[k]) st = k;
    }
  }
  Size[0] = 0;
  used.resize(0);
  used.resize(n + 1, 0);
  DFS2(y);
  cout << H[fin] - 1;
  return 0;
}
