#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator<(const Edge& lhs, const Edge& rhs) {
    return lhs.cost < rhs.cost;
  };
  friend bool operator>(const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator<=(const Edge& lhs, const Edge& rhs) {
    return !(lhs > rhs);
  };
  friend bool operator>=(const Edge& lhs, const Edge& rhs) {
    return !(lhs < rhs);
  };
};
template <typename T>
using Edges = vector<Edge<T> >;
template <typename T>
using Graph = vector<Edges<T> >;
using graph = Graph<int>;
int du[100001];
int dv[100001];
void bfs(graph& g, int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < 100001; ++i) du[i] = -1;
  du[s] = 0;
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (auto e : g[f]) {
      if (du[e.to] >= 0) continue;
      du[e.to] = du[f] + 1;
      q.push(e.to);
    }
  }
}
void bfs2(graph& g, int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < 100001; ++i) dv[i] = -1;
  dv[s] = 0;
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (auto e : g[f]) {
      if (dv[e.to] >= 0) continue;
      dv[e.to] = dv[f] + 1;
      q.push(e.to);
    }
  }
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  graph g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
  }
  bfs(g, u);
  bfs2(g, v);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (du[i] > dv[i]) continue;
    if (du[i] == dv[i]) {
      ans = min(ans, du[i]);
      continue;
    }
    ans = max(ans, dv[i] - 1);
  }
  cout << ans << endl;
}
