#include <bits/stdc++.h>
using namespace std;
int n, a, b, maxdep, maxpos, partmaxdep, lca, depth[100010], check[100010],
    parent[100010];
vector<int> v[100010];
void dfs(int x, int d, int k) {
  depth[x] = d;
  if (maxdep < d) {
    maxdep = d;
    maxpos = x;
  }
  if (k || x == a) {
    partmaxdep = max(partmaxdep, d);
  }
  check[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (!check[v[x][i]]) {
      parent[v[x][i]] = x;
      if (x == a) {
        dfs(v[x][i], d + 1, 1);
      } else {
        dfs(v[x][i], d + 1, k);
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &a, &b);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(b, 0, 0);
  int u = a, v = maxpos;
  while (depth[u] > depth[v]) {
    u = parent[u];
  }
  while (depth[v] > depth[u]) {
    v = parent[v];
  }
  while (u != v) {
    u = parent[u];
    v = parent[v];
  }
  lca = u;
  if (depth[lca] <= depth[a] - depth[lca]) {
    printf("%d", partmaxdep - 1);
  } else {
    printf("%d", maxdep - 1);
  }
}
