#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int n, x, y, h[200005], u, v, wh;
int lastNode[200005], big[200005], ans;
bool onPath[200005];
void dfs1(int nod, int hei, int lst = -1) {
  lastNode[nod] = lst;
  h[nod] = hei;
  if (nod == u) {
    int curr = nod;
    while (curr != -1) {
      onPath[curr] = true;
      curr = lastNode[curr];
    }
  }
  for (auto x : g[nod]) {
    if (x == lst) {
      continue;
    }
    dfs1(x, hei + 1, nod);
  }
}
void dfs2(int nod, int lst = -1) {
  for (auto x : g[nod]) {
    if (x == lst || !onPath[x]) {
      continue;
    }
    if (h[x] > h[u] - h[x]) {
      ans = max(ans, big[x] - 1);
    }
    if (nod != u) {
      dfs2(x, nod);
    }
  }
}
void dfs3(int nod, int lst = -1) {
  int leaf = true;
  for (auto x : g[nod]) {
    if (x == lst) {
      continue;
    }
    leaf = false;
    dfs3(x, nod);
  }
  if (leaf) {
    big[nod] = 1;
  } else {
    int maxx = 1;
    for (auto x : g[nod]) {
      if (x == lst) {
        continue;
      }
      maxx = max(maxx, big[x]);
    }
    big[nod] = maxx + 1;
  }
}
int main() {
  cin >> n >> u >> v;
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs1(v, 0);
  dfs3(v);
  dfs2(v);
  cout << ans << '\n';
  return 0;
}
