#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod2 = 998244353;
const int INF = 1e9;
const long double EPS = 1e-10;
const int MAX = 100005;
vector<int> G[MAX];
int dt[MAX], da[MAX];
vector<int> d1[MAX], d2[MAX];
bool visited[MAX];
void dfs(int u) {
  for (int v : G[u]) {
    if (dt[v] != INF) continue;
    dt[v] = dt[u] + 1;
    dfs(v);
  }
}
void dfs2(int u) {
  for (int v : G[u]) {
    if (da[v] != INF) continue;
    da[v] = da[u] + 1;
    dfs2(v);
  }
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 0; i < (n); ++i) dt[i] = INF;
  dt[u] = 0;
  dfs(u);
  for (int i = 0; i < (n); ++i) da[i] = INF;
  da[v] = 0;
  dfs2(v);
  for (int i = 0; i < (n); ++i) {
    if (dt[i] == INF) continue;
    d1[dt[i]].push_back(i);
  }
  for (int i = 0; i < (n); ++i) {
    if (da[i] == INF) continue;
    d2[da[i]].push_back(i);
  }
  for (int i = 0; i < (n); ++i) {
    bool flag = false;
    for (int x1 : d1[i]) {
      if (!visited[x1]) {
        flag = true;
      }
    }
    if (!flag) {
      cout << i - 1 << endl;
      return 0;
    }
    for (int x2 : d2[i]) {
      visited[x2] = true;
    }
    flag = false;
    for (int x1 : d1[i]) {
      if (!visited[x1]) {
        d1[i + 2].push_back(x1);
        flag = true;
      }
    }
    if (!flag) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
