#include <bits/stdc++.h>
using namespace std;
const int MM = 1e9;
const int MOD = MM + 7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, 1, -1};
template <typename T>
T GCD(T u, T v) {
  return v ? GCD(v, u % v) : u;
}
template <typename T>
T LCM(T x, T y) {
  T gc = GCD(x, y);
  return x * y / gc;
}
struct Edge {
  long long to, cost;
};
void DFS(vector<vector<Edge> > &G, vector<long long> &color, int now) {
  queue<long long> que;
  que.push(now);
  while (que.size()) {
    int pos = que.front();
    que.pop();
    for (int i = 0; i < G[pos].size(); i++) {
      Edge es = G[pos][i];
      if (color[es.to] != -1) continue;
      if (es.cost % 2 == 0) {
        color[es.to] = color[pos];
      } else {
        color[es.to] = !color[pos];
      }
      que.push(es.to);
    }
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int> > g(N);
  vector<int> dist(N, MM), Takahashi(N, MM);
  dist[u] = 0;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> que;
  que.push(u);
  while (que.size()) {
    int pos = que.front();
    que.pop();
    for (int i = 0; i < g[pos].size(); i++) {
      int now = g[pos][i];
      if (dist[now] != MM) continue;
      dist[now] = dist[pos] + 1;
      que.push(now);
    }
  }
  Takahashi[v] = 0;
  que.push(v);
  while (que.size()) {
    int pos = que.front();
    que.pop();
    for (int i = 0; i < g[pos].size(); i++) {
      int now = g[pos][i];
      if (Takahashi[now] != MM) continue;
      Takahashi[now] = Takahashi[pos] + 1;
      que.push(now);
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (Takahashi[i] >= dist[i]) {
      ans = max(ans, dist[i]);
    }
  }
  cout << ans << endl;
}
