#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using P = pair<T, U>;
template <class T>
using Heap = priority_queue<T>;
template <class T>
using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U>
using umap = unordered_map<T, U>;
template <class T>
using uset = unordered_set<T>;
template <class T>
bool ChangeMax(T& a, const T& b) {
  if (a >= b) return false;
  a = b;
  return true;
}
template <class T>
bool ChangeMin(T& a, const T& b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T, size_t N, class U>
void Fill(T (&a)[N], const U& v) {
  fill((U*)a, (U*)(a + N), v);
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& e : v) is >> e;
  return is;
}
int n, tak, aok;
vector<set<int>> v;
vector<int> tak_dis;
vector<int> aok_dis;
vector<int> ans_vec;
void Init() {
  v.resize(n);
  tak_dis.resize(n);
  aok_dis.resize(n);
  ans_vec.resize(n);
}
void Bfs(int s, bool isT) {
  bitset<100010> bs;
  queue<P<int, int>> que;
  que.push({s, 0});
  while (!que.empty()) {
    int now = que.front().first;
    int dis = que.front().second;
    bs[now] = 1;
    if (isT)
      tak_dis[now] = dis;
    else
      aok_dis[now] = dis;
    que.pop();
    for (auto& e : v[now]) {
      if (bs[e]) continue;
      bs[e] = 1;
      que.push({e, dis + 1});
    }
  }
}
int Bfs2(int s) {
  int ans = 0;
  bitset<100010> bs;
  queue<P<int, int>> que;
  que.push({s, 0});
  while (!que.empty()) {
    int now = que.front().first;
    int dis = que.front().second;
    ans_vec[now] = dis;
    ChangeMax(ans, aok_dis[now]);
    que.pop();
    cerr << "now + 1" << ':' << now + 1 << endl;
    ;
    cerr << "dis" << ':' << dis << endl;
    ;
    cerr << "tak_dis[now]" << ':' << tak_dis[now] << endl;
    ;
    cerr << "aok_dis[now]" << ':' << aok_dis[now] << endl;
    ;
    bs[now] = 1;
    if (tak_dis[now] == aok_dis[now]) continue;
    for (auto& e : v[now]) {
      if (tak_dis[e] > aok_dis[e]) continue;
      if (bs[e]) continue;
      bs[e] = 1;
      que.push({e, dis + 1});
    }
  }
  return ans;
}
int main() {
  cin >> n >> tak >> aok;
  tak--;
  aok--;
  Init();
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].insert(b);
    v[b].insert(a);
  }
  cerr << 106 << endl;
  ;
  Bfs(tak, true);
  cerr << 108 << endl;
  ;
  Bfs(aok, false);
  cerr << 110 << endl;
  ;
  cout << Bfs2(tak) << endl;
  return 0;
}
