#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long INF = 1e18;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
T pow(T a, int b) {
  return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
const int mod = 1000000007;
long long modpow(long long a, int b) {
  return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  for (auto& vi : vec) os << vi << " ";
  return os;
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
}
void solve() {
  int n;
  int p[2];
  cin >> n >> p[0] >> p[1];
  p[0]--;
  p[1]--;
  vector<vector<int> > g(n);
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  vector<vector<int> > table(2, vector<int>(n, inf));
  for (int key = 0; key < (2); ++key) {
    queue<int> q;
    q.push(p[key]);
    table[key][p[key]] = 0;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int nxt : g[now]) {
        if (chmin(table[key][nxt], table[key][now] + 1)) {
          q.push(nxt);
        }
      }
    }
  }
  int id = -1, ma = -1;
  for (int i = 0; i < (n); ++i)
    if (table[0][i] < table[1][i] && chmax(ma, table[0][i])) {
      id = i;
    }
  cout << table[1][g[id][0]] << endl;
}
