#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 10000000000000000;
double PI = 3.1415926535;
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
using Graph = vector<vector<long long>>;
Graph G(100010);
queue<long long> Q;
void bfs(long long s, vector<long long>& table) {
  for (int i = 0; i < table.size(); i++) {
    table[i] = INF;
  }
  table[s] = 0;
  Q.push(s);
  while (Q.size()) {
    long long x = Q.front();
    long long n = G[x].size();
    Q.pop();
    for (long long i = 0; i < n; i++) {
      long long y = G[x][i];
      if (table[y] == INF) {
        table[y] = table[x] + 1;
        Q.push(y);
      }
    }
  }
  return;
}
void dfs(long long x, long long a, vector<bool>& frag,
         vector<long long> tableT) {
  long long n = G[x].size();
  long long d = tableT[x];
  for (int i = 0; i < n; i++) {
    int y = G[x][i];
    if (y != a && tableT[y] == d + 1) {
      frag[y] = 0;
      dfs(y, x, frag, tableT);
    }
  }
}
int main() {
  long long N, U, V;
  cin >> N >> U >> V;
  U--;
  V--;
  for (int i = 0; i < N - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<long long> tableA(100010), tableT(100010);
  vector<bool> frag(100010);
  for (int i = 0; i < 100010; i++) {
    frag[i] = 1;
  }
  bfs(V, tableA);
  bfs(U, tableT);
  for (int i = 0; i < N; i++) {
    if (tableA[i] == tableT[i]) {
      dfs(i, -1, frag, tableT);
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (frag[i]) {
      ans = max(ans, tableA[i]);
    }
  }
  cout << ans - 1 << endl;
}
