#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  long long to, cap, rev;
  Edge(long long _to, long long _cap, long long _rev) {
    to = _to;
    cap = _cap;
    rev = _rev;
  }
};
void add_edge(vector<vector<Edge> >& G, long long from, long long to,
              long long cap, bool revFlag, long long revCap) {
  G[from].push_back(Edge(to, cap, (long long)G[to].size()));
  if (revFlag)
    G[to].push_back(Edge(from, revCap, (long long)G[from].size() - 1));
}
void Dijkstra(vector<vector<Edge> >& G, long long s, vector<long long>& d) {
  d.resize(G.size());
  for (long long(i) = 0; (i) < (d.size()); (i)++) d[i] = INF;
  d[s] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      q;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    pair<long long, long long> a = q.top();
    q.pop();
    if (d[a.second] < a.first) continue;
    for (long long(i) = 0; (i) < (G[a.second].size()); (i)++) {
      Edge e = G[a.second][i];
      if (d[e.to] > d[a.second] + e.cap) {
        d[e.to] = d[a.second] + e.cap;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<Edge> > g(n);
  for (long long(i) = 0; (i) < (n - 1); (i)++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    add_edge(g, a, b, 1, true, 1);
  }
  vector<long long> d;
  Dijkstra(g, v, d);
  vector<long long> dt;
  Dijkstra(g, u, dt);
  long long ans = 0;
  for (long long(i) = 0; (i) < (n); (i)++) {
    if (d[i] >= dt[i]) {
      if (d[i] % 2 == dt[i] % 2) {
        chmax(ans, d[i]);
      } else {
        chmax(ans, d[i] + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
