#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int vis[maxn], head[maxn], dis1[maxn], dis2[maxn];
struct edge {
  int u, v, nxt;
} es[maxn * 2];
vector<int> E;
int n, s, e, tot, maxd;
void add(int u, int v) {
  es[++tot].u = u;
  es[tot].v = v;
  es[tot].nxt = head[u];
  head[u] = tot;
}
void bfs(int s, int d[]) {
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(s);
  vis[s] = 1;
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = es[i].nxt) {
      int v = es[i].v;
      if (vis[v]) continue;
      d[v] = d[u] + 1;
      maxd = max(maxd, d[v]);
      q.push(v);
      vis[v] = 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  memset(head, -1, sizeof(head));
  cin >> n >> s >> e;
  tot = -1;
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  bfs(s, dis2);
  maxd = 0;
  bfs(e, dis1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dis2[i] < dis1[i]) {
      int t = dis1[i] - dis2[i];
      if (t & 1 || t <= 2)
        ans = max(ans, maxd - 1);
      else
        ans = max(ans, maxd);
    }
  }
  cout << ans << endl;
  return 0;
}
