#include <bits/stdc++.h>
using namespace std;
vector<long long> udist(100005, -1);
vector<long long> vdist(100005, -1);
vector<long long> visited(100005, -1);
vector<vector<long long>> g;
vector<long long> newdist(100005, -1);
template <class T>
void show_1d_vector(const vector<T> &v) {
  for (auto v1 : v) {
    cout << v1 << " ";
  }
  cout << endl;
}
void dfs(long long now, long long depth, bool is_u) {
  if (is_u) {
    udist[now] = depth;
    for (int i = 0; i < g[now].size(); i++) {
      if (udist[g[now][i]] == -1) {
        dfs(g[now][i], depth + 1, is_u);
      }
    }
  } else {
    vdist[now] = depth;
    for (int i = 0; i < g[now].size(); i++) {
      if (vdist[g[now][i]] == -1) {
        dfs(g[now][i], depth + 1, is_u);
      }
    }
  }
}
vector<long long> path;
void dfs2(long long now, long long depth) {
  path.push_back(now);
  if (depth == 0) {
    return;
  }
  for (int i = 0; i < g[now].size(); i++) {
    if (udist[g[now][i]] == depth - 1) {
      dfs2(g[now][i], depth - 1);
    }
  }
}
bool flg = true;
long long bfs(long long st) {
  queue<long long> q;
  long long start = st;
  q.push(start);
  visited[start] = 0;
  long long ret = 0;
  while (!q.empty()) {
    long long now = q.front();
    q.pop();
    for (int i = 0; i < g[now].size(); i++) {
      long long next = g[now][i];
      if (visited[next] == -1 && newdist[next] != 9999999) {
        flg = false;
        q.push(next);
        visited[next] = visited[now] + 1;
        ret = max(ret, visited[now] + 1);
      }
    }
  }
  return ret;
}
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(u, 0, true);
  dfs(v, 0, false);
  long long dist1 = udist[v];
  dfs2(v, dist1);
  long long start;
  long long ans = 0;
  if (dist1 <= 2) {
    start = u;
    if (dist1 == 2) {
      for (int i = 0; i < 100005; i++) {
        if (vdist[i] <= 1) {
          newdist[i] = 9999999;
        }
      }
    }
    newdist[v] = 9999999;
  } else {
    if (path.size() % 2 == 0) {
      start = path[path.size() / 2];
      ans += path.size() / 2 - 1;
    } else {
      start = path[path.size() / 2 + 1];
      ans += path.size() / 2 - 1;
    }
    for (int i = 0; i < path.size() / 2; i++) {
      newdist[path[i]] = 9999999;
    }
  }
  long long ret = bfs(start);
  ans += ret;
  if (dist1 == 2 && flg) {
    cout << 1 << endl;
  } else if (dist1 == 1 && flg) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
