#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int INF = 1e9;
int used[100000];
struct edge {
  int to, num;
};
int main() {
  int N, s, t;
  cin >> N >> s >> t;
  s--;
  t--;
  vector<edge> G[N];
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  int d[N];
  for (int i = 0; i < N; i++) d[i] = INF;
  d[s] = 0;
  queue<int> que;
  que.push(s);
  while (que.size()) {
    int aa = que.front();
    que.pop();
    for (int i = 0; i < G[aa].size(); i++) {
      if (d[G[aa][i].to] == INF) {
        d[G[aa][i].to] = d[aa] + 1;
        que.push(G[aa][i].to);
      }
    }
  }
  int now = t;
  vector<int> path;
  path.push_back(now);
  for (int i = 0; i < d[t]; i++) {
    for (int j = 0; j < G[now].size(); j++) {
      if (d[G[now][j].to] == d[now] - 1) {
        used[G[now][j].num] = 1;
        now = G[now][j].to;
        path.push_back(now);
        break;
      }
    }
  }
  int len = path.size() - 1, ans = 0;
  vector<int> d2(N, INF);
  for (int i = 0; i <= (len - 1) / 2; i++) {
    queue<int> qu;
    qu.push(path[len - i]);
    int cnt = 0;
    d2[path[len - i]] = 0;
    while (qu.size()) {
      int aa = qu.front();
      qu.pop();
      for (int j = 0; j < G[aa].size(); j++) {
        if (used[G[aa][j].num] == 1) continue;
        if (d2[G[aa][j].to] == INF) {
          d2[G[aa][j].to] = d[aa] + 1;
          if (cnt < d2[G[aa][j].to]) cnt = d2[G[aa][j].to];
          qu.push(d2[G[aa][j].to]);
        }
      }
    }
    if (ans < cnt + len - i) ans = cnt + len - i;
  }
  cout << ans - 1 << endl;
  return 0;
}
