#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
struct edge {
  long long to, cost;
};
struct graph {
  long long V;
  vector<vector<edge> > G;
  vector<long long> d;
  graph(long long n) { init(n); }
  void init(long long n) {
    V = n;
    G.resize(V);
    d.resize(V);
    for (int i = 0; i < V; i++) {
      d[i] = LONG_MAX;
    }
  }
  void add_edge(long long s, long long t, long long cost) {
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }
  void dijkstra(long long s) {
    for (int i = 0; i < V; i++) {
      d[i] = LONG_MAX;
    }
    d[s] = 0;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        que;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty()) {
      pair<long long, long long> p = que.top();
      que.pop();
      long long v = p.second;
      if (d[v] < p.first) continue;
      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(pair<long long, long long>(d[e.to], e.to));
        }
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  graph g(n);
  graph f(n);
  vector<int> a(n), b(n);
  for (long long i = 0; i < (long long)(n - 1); i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g.add_edge(a[i], b[i], 1);
    g.add_edge(b[i], a[i], 1);
    f.add_edge(a[i], b[i], 1);
    f.add_edge(b[i], a[i], 1);
  }
  g.dijkstra(u - 1);
  f.dijkstra(v - 1);
  if (g.G[u - 1].size() == 1) {
    for (edge x : g.G[v - 1]) {
      if (g.G[u - 1][0].to == x.to) {
        cout << 1 << endl;
        return 0;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    if (g.d[i] < f.d[i]) {
      if ((-g.d[i] + f.d[i]) % 2 == 1)
        ans = max(ans, f.d[i] - 1);
      else
        ans = max(ans, f.d[i]);
    } else if (g.d[i] > f.d[i]) {
      continue;
    } else {
      ans = max(ans, 2 * g.d[i] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
