#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
void useiostream() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(8);
}
void drop(char const* bu) {
  printf("%s", bu);
  exit(0);
}
ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ld const pi = acos(-1.0L);
ld const eps = 0.0001L;
template <typename T, typename TT>
bool mi(T& a, TT b) {
  return a > b ? (a = b, true) : false;
}
template <typename T, typename TT>
bool ma(T& a, TT b) {
  return a < b ? (a = b, true) : false;
}
mt19937 ran(996);
int const mod = 1000000007;
ull bm(ull a, ull p, ull mod) {
  return (a * p - (ll)((ld)a * p / mod) * mod + mod) % mod;
}
ull bp(ull a, ull p, ull mod) {
  ull re = 1;
  while (p) {
    if (p & 1) re = bm(re, a, mod);
    p >>= 1;
    a = bm(a, a, mod);
  }
  return re;
}
int n;
int s, t;
vector<int> g[100005];
int d[100005];
int mxinf = INT_MIN;
int ver = -1;
void dfs(int start, int deep) {
  d[start] = deep;
  if (deep > mxinf) {
    mxinf = deep;
    ver = start;
  }
  for (auto& x : g[start]) {
    if (d[x] == -1) dfs(x, deep + 1);
  }
}
int main() {
  useiostream();
  for (auto& x : d) {
    x = -1;
  }
  cin >> n >> s >> t;
  s--;
  t--;
  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);
  }
  dfs(s, 0);
  int le1 = d[ver];
  for (auto& x : d) x = -1;
  dfs(t, 0);
  int le2 = d[ver];
  cout << max(le1, le2) - 1;
  return 0;
}
