#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1e9;
const long double EPS = 1e-10;
const int MAX = 100005;

vector<int> G[MAX];
int dt[MAX];
pair<int, int> da[MAX];
vector<int> d1[MAX];
bool visited[MAX];

void dfs(int u) {
  for (int v: G[u]) {
    if (dt[v] != -1) continue;
    dt[v] = dt[u] + 1;
    dfs(v);
  }
}

void dfs2(int u) {
  for (int v: G[u]) {
    if (da[v].first != -1) continue;
    da[v].first = da[u].first + 1;
    dfs2(v);
  }
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i, n) dt[i] = -1;
  dt[u] = 0;
  dfs(u);

  rep(i, n) da[i] = {-1, i};
  da[v] = 0;
  dfs2(v);
  sort(da.begin(), da.end());

  rep(i, n) {
    d1[dt[i]].push_back(i);
  }
  rep(i, n) {
    d2[da[i]].push_back(i);
  }

  int idxa = 0;

  rep(i, n) {
    bool flag = false;
    for (int x1: d1[i]) {
      if (!visited[x1]) {
        flag = true;
      }
    }
    if (!flag) {
      cout << i - 1 << endl;
      return 0;
    }
    
    while (idxa < n && da[idxa].first <= i) {
      visited[da[idxa].second] = true;
      idxa++;
    }

    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;
}