#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;
long long int N, U, V;
vector<long long int> maxDepth, distFromV, distFromU;
vector<vector<long long int>> AdjList;
long long int maxAdim = 0, yukari;
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  freopen("output.txt", "w", stdout);
  cin >> N >> U >> V;
  U--;
  V--;
  AdjList.resize(N);
  distFromU.resize(N, INF);
  distFromV.resize(N, INF);
  for (long long int i = 0; i < N - 1; ++i) {
    long long int u, v;
    cin >> u >> v;
    u--;
    v--;
    AdjList[u].push_back(v);
    AdjList[v].push_back(u);
  }
  queue<pair<long long int, long long int>> bfs;
  vector<bool> visited(N, false);
  bfs.push(make_pair(U, 0));
  visited[U] = true;
  distFromU[U] = 0;
  while (!bfs.empty()) {
    pair<long long int, long long int> tp = bfs.front();
    bfs.pop();
    for (long long int i = 0; i < AdjList[tp.first].size(); ++i) {
      long long int v = AdjList[tp.first][i];
      if (visited[v]) continue;
      visited[v] = true;
      distFromU[v] = tp.second + 1;
      bfs.push(make_pair(v, tp.second + 1));
    }
  }
  bfs.push(make_pair(V, 0));
  visited.assign(N, false);
  visited[V] = true;
  distFromV[V] = 0;
  while (!bfs.empty()) {
    pair<long long int, long long int> tp = bfs.front();
    bfs.pop();
    for (long long int i = 0; i < AdjList[tp.first].size(); ++i) {
      long long int v = AdjList[tp.first][i];
      if (visited[v]) continue;
      visited[v] = true;
      distFromV[v] = tp.second + 1;
      bfs.push(make_pair(v, tp.second + 1));
    }
  }
  bool sifir = true;
  long long int ans = 0;
  if (AdjList[U].size() == 1 and AdjList[U][0] == V) {
    cout << 0 << '\n';
    return 0;
  }
  long long int maxy = 0;
  for (long long int i = 0; i < N; ++i) {
    long long int v = AdjList[U][i];
    maxy = max(distFromU[v], maxy);
    if (distFromV[v] > distFromU[U]) {
      sifir = false;
      break;
    }
  }
  if (sifir) {
    cout << maxy << '\n';
    return 0;
  }
  for (long long int i = 0; i < N; ++i) {
    ans = max(ans, distFromU[i] + ((distFromV[i] - distFromU[i]) & 1
                                       ? distFromV[i] - distFromU[i] - 1
                                       : distFromV[i] - distFromU[i] - 1));
  }
  cout << ans << '\n';
  return 0;
}
