#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;
const Int dy[] = {-1, 0, 1, 0};
const Int dx[] = {0, 1, 0, -1};
template <typename T>
void reverse(vector<T> &v) {
  reverse(v.begin(), v.end());
}
template <typename T>
void sort(vector<T> &v) {
  sort(v.begin(), v.end());
}
template <typename T>
void rsort(vector<T> &v) {
  sort(v.rbegin(), v.rend());
}
template <typename T>
T sum(const vector<T> &v) {
  return accumulate(v.begin(), v.end(), T(0));
}
template <class T>
void update_max(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
void update_min(T &a, const T &b) {
  a = min(a, b);
}
vector<pair<char, Int>> merge_cont_char(const string &s) {
  vector<pair<char, Int>> ret;
  if (s.empty()) return ret;
  ret.push_back(make_pair(s[0], 0));
  for (auto &&c : s) {
    if (ret.back().first == c)
      ret.back().second++;
    else
      ret.push_back(make_pair(c, 1));
  }
  return ret;
}
class Shakutori {
 public:
  Int head, tail, end = 0;
  bool moveHead() {
    if (head == end) {
      return false;
    }
    head++;
    return true;
  }
  void moveTail() { tail++; }
  bool valid() {
    if (head == tail) return true;
    return true;
  }
  void solve() {
    head = tail = 0;
    Int ans = 0;
    while (moveHead()) {
      while (!valid()) {
        moveTail();
      }
    }
  }
};
class Solver {
 public:
  Int ans = 0, N, U, V;
  vvi G;
  vi UD, VD;
  set<Int> visited;
  Solver() {}
  void input() {
    cin >> N >> U >> V;
    U--;
    V--;
    UD = VD = vi(N, -1);
    G = vvi(N);
    for (Int i = 0; i < Int(N - 1); i++) {
      Int a, b;
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }
  void dfs(vi &cost, Int now) {
    for (auto &&e : G[now]) {
      if (cost[e] != -1) continue;
      cost[e] = cost[now] + 1;
      dfs(cost, e);
    }
  }
  void dfs2(Int now) {
    visited.insert(now);
    ;
    ;
    ;
    if (UD[now] % 2 == VD[now] % 2) {
      ans = max(ans, max(UD[now], VD[now]));
    } else {
      ans = max(ans, max(UD[now] - 1, VD[now]));
    }
    if (UD[now] >= VD[now]) {
      return;
    }
    for (auto &&e : G[now]) {
      if (visited.count(e)) continue;
      dfs2(e);
    }
  }
  void solve() {
    ans = 0;
    dfs(VD, V);
    dfs(UD, U);
    dfs2(U);
  }
  void output() { cout << ans << endl; }
};
void initilization() {
  struct BoolName : numpunct<char> {
    string t, f;
    BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
    string do_truename() const { return t; }
    string do_falsename() const { return f; }
  };
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(15) << boolalpha;
  cout.imbue(locale(cout.getloc(), new BoolName));
}
int main() {
  initilization();
  Solver s;
  s.input();
  s.solve();
  s.output();
  return 0;
}
