#include <bits/stdc++.h>
using namespace std;
using Pi = pair<int, int>;
using ll = long long;
string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}
template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}
template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}
template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}
template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}
ll euclidean_gcd(ll a, ll b) {
  if (a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, U, V;
  cin >> N >> U >> V;
  vector<vector<int>> G(N);
  for (int i = 0; i < (int)N - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vector<int> dista(N), distb(N);
  int teban = 0;
  function<void(int, int)> dfs = [&](int u, int pre) {
    for (int v : G[u]) {
      if (pre != v) {
        if (teban == 0) {
          dista[v] = dista[u] + 1;
        } else {
          distb[v] = distb[u] + 1;
        }
        dfs(v, u);
      }
    }
  };
  dfs(U - 1, -1);
  teban = 1;
  dfs(V - 1, -1);
  int ans = 0;
  for (int i = 0; i < (int)N; i++) {
    if (G[i].size() == 1) {
      int v = G[i][0];
      if (distb[U - 1] % 2 == 0) {
        if (dista[v] <= distb[v]) {
          ans = max(ans, distb[v]);
        }
      } else {
        if (dista[i] < distb[i]) {
          ans = max(ans, dista[i]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
