#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int next, to;
} edge[100005 * 2];
int fi[100005], n, se, ans = 0, que[100005], s, t, dep[100005], U, V;
bool vis[100005];
inline void add_edge(int u, int v) {
  edge[++se].next = fi[u], edge[se].to = v, fi[u] = se;
}
inline void add(int u, int v) { add_edge(u, v), add_edge(v, u); }
void bfs() {
  dep[U] = dep[V] = 1;
  que[t++] = U, que[t++] = V, vis[V] = 1;
  while (s < t) {
    int u = que[s++];
    if (!dep[u]) continue;
    for (int i = fi[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (dep[v]) {
        if (vis[v] == vis[u]) continue;
        if (!vis[v]) {
          if (dep[v] == dep[u] + 1)
            ans = max(ans, dep[v]), dep[v] = 0;
          else
            vis[v] = 1, que[t++] = v, dep[v] = dep[u] + 1;
          ans = max(ans, dep[v] - 1);
        }
      } else
        dep[v] = dep[u] + 1, vis[v] = vis[u], que[t++] = v;
    }
  }
}
int main() {
  int u, v;
  scanf("%d%d%d", &n, &U, &V);
  for (int i = 1; i < n; i++) scanf("%d%d", &u, &v), add(u, v);
  bfs();
  printf("%d", U == V ? 0 : ans - 1);
  return 0;
}
