#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
long long n, u, v;
vector<long long> order;
bool flag = false;
bool used[100005];
vector<long long> g[100005];
long long ans = 0;
void dfs(long long ver) {
  if (!flag) order.push_back(ver);
  used[ver] = 1;
  if (ver == u) {
    flag = 1;
    return;
  }
  for (int i = 0; i < g[ver].size(); i++) {
    long long to = g[ver][i];
    if (!used[to]) {
      dfs(to);
    }
  }
  if (!flag) order.pop_back();
}
void dfs1(long long ver, long long cnt) {
  used[ver] = 1;
  if (g[ver].size() == 1) {
    ans = max(ans, cnt);
  }
  for (long long i = 0; i < g[ver].size(); i++) {
    long long to = g[ver][i];
    if (!used[to]) {
      dfs1(to, cnt + 1);
    }
  }
}
int main() {
  cin >> n >> u >> v;
  for (int i = 2; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(v);
  long long x = order.size();
  long long vr, cnt = 0;
  if (x % 2) {
    cnt = x / 2 + 1;
    vr = order[cnt];
  } else {
    cnt = x / 2;
    vr = order[cnt];
  }
  if (g[v].size() == 1 and order.size() < 4 and u != v) {
    cout << 1;
    return 0;
  }
  if (u == v) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) used[i] = 0;
  used[order[cnt - 1]] = 1;
  used[order[cnt]] = 1;
  dfs1(vr, 0);
  cout << cnt + ans;
}
