#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int LOG = 19;
struct HLD {
  int n;
  vector<int> g[MAXN];
  int dep[MAXN];
  int prt[MAXN][LOG];
  void dfssz(int u, int p) {
    dep[u] = dep[p] + 1;
    prt[u][0] = p;
    for (int &v : g[u])
      if (v != p) {
        dep[v] = dep[u] + 1;
        dfssz(v, u);
      }
  }
  inline int lca(int a, int b) {
    if (dep[a] > dep[b]) swap(a, b);
    int diff = dep[b] - dep[a];
    for (int k = (LOG - 1); k >= (0); k--)
      if (diff & (1 << k)) {
        b = prt[b][k];
      }
    if (a == b) return a;
    for (int k = (LOG - 1); k >= (0); k--)
      if (prt[a][k] != prt[b][k]) {
        a = prt[a][k];
        b = prt[b][k];
      }
    return prt[a][0];
  }
  void init(int _n) {
    n = _n;
    for (int i = (1); i <= (n); i++) g[i].clear();
  }
  void addEdge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  void yutruli() {
    dfssz(1, 0);
    for (int k = (1); k <= (LOG - 1); k++)
      for (int i = (1); i <= (n); i++) prt[i][k] = prt[prt[i][k - 1]][k - 1];
  }
  int dist(int x, int y) {
    int l = lca(x, y);
    return dep[x] + dep[y] - 2 * dep[l];
  }
} tree;
int n;
int s, t;
bool close[MAXN];
int dp[MAXN];
int len;
void dfs(int now, int d, int fa) {
  if (d <= len)
    close[now] = 1;
  else
    return;
  for (int x : tree.g[now]) {
    if (x == fa) continue;
    dfs(x, d + 1, now);
  }
}
int D;
void search(int now, int d, int fa) {
  if (close[now]) return;
  dp[now] = d;
  if (dp[now] > dp[D]) D = now;
  for (int x : tree.g[now]) {
    if (x == fa) continue;
    search(x, d + 1, now);
  }
}
int main() {
  cin >> n;
  cin >> s >> t;
  tree.init(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    tree.addEdge(x, y);
  }
  tree.yutruli();
  int L = tree.dist(s, t);
  len = L / 2;
  dfs(t, 0, t);
  D = s;
  search(s, 0, s);
  int dt = tree.dist(D, t);
  int ds = tree.dist(D, s);
  int ans = 0;
  while (ds != dt || ans < len) {
    if (ds == 0)
      ds++;
    else
      ds--;
    if (ds == dt && ans >= len) break;
    dt--;
    ans++;
    if (ds == dt && ans >= len) break;
  }
  printf("%d\n", ans);
  return 0;
}
