#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const long long INF = 1e18;
const int MX = 100005;
int N, U, V, A, B;
vector<int> tree[MX];
int parent[MX], depth[MX], maxDepth[MX];
long long ans;
int dfs(int v, int p) {
  depth[v] = depth[p] + 1;
  int maxD = depth[v];
  for (auto& u : tree[v]) {
    if (!depth[u]) {
      parent[u] = v;
      maxD = max(maxD, dfs(u, v));
    }
  }
  maxDepth[v] = maxD;
  return maxD;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> U >> V;
  for (int i = (0); i < (N - 1); ++i) {
    cin >> A >> B;
    tree[A].push_back(B);
    tree[B].push_back(A);
  }
  dfs(V, 0);
  ans += (depth[U] - depth[V] - 1) / 2;
  for (int i = (0); i < (ans); ++i) U = parent[U];
  ans += maxDepth[U] - depth[U];
  int vDepth = 1 + ans, cDepth = maxDepth[U];
  while (vDepth != cDepth) {
    if (cDepth == maxDepth[cDepth]) cDepth--;
    if (vDepth == cDepth) break;
    vDepth++;
    ans++;
  }
  cout << ans;
  return 0;
}
