#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> Parent;
  UnionFind(int N) { Parent = vector<int>(N, -1); }
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  int size(int A) { return -Parent[root(A)]; }
  bool connect(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) {
      return false;
    }
    if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
bool check(pair<long long int, long long int> a,
           pair<long long int, long long int> b) {
  return a > b;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long int convination(long long int a, long long int b) {
  long long int ans = 1;
  for (long long int i = 0; i < b; i++) {
    ans *= a - i;
    ans %= 1000000007;
  }
  for (long long int i = 1; i <= b; i++) {
    ans *= modinv(i, 1000000007);
    ans %= 1000000007;
  }
  return ans;
}
long long int power(long long int a, long long int b) {
  if (b == 1) return a;
  if (b == 0) return 1;
  long long int tmp = power(a, (long long int)b / 2);
  tmp *= tmp;
  tmp %= long long int(1e9 + 7);
  if (b % 2 == 1) {
    tmp *= a;
    tmp %= long long int(1e9 + 7);
  }
  return tmp;
}
bool dfs(int p, int goal, vector<vector<int>>& a, vector<int>& cost,
         vector<bool> visited) {
  if (visited[p]) return false;
  visited[p] = true;
  for (int i = 0; i < a[p].size(); i++) {
    if (a[p][i] == goal) {
      return true;
    } else {
      if (dfs(a[p][i], goal, a, cost, visited)) {
        cost[a[p][i]] = -1;
        return true;
      }
    }
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<int>> a(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  vector<int> cost(n, 100000);
  vector<bool> visited(n, false);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  que.push({0, u});
  while (que.size() != 0) {
    auto top = que.top();
    que.pop();
    if (visited[top.second]) continue;
    visited[top.second] = true;
    cost[top.second] = top.first;
    for (int i = 0; i < a[top.second].size(); i++) {
      que.push({top.first + 1, a[top.second][i]});
    }
  }
  vector<int> cost_v(n, 100000);
  vector<bool> visited2(n, false);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que2;
  que2.push({0, v});
  while (que2.size() != 0) {
    auto top = que2.top();
    que2.pop();
    if (visited2[top.second]) continue;
    visited2[top.second] = true;
    cost_v[top.second] = top.first;
    for (int i = 0; i < a[top.second].size(); i++) {
      que2.push({top.first + 1, a[top.second][i]});
    }
  }
  fill(visited.begin(), visited.end(), false);
  dfs(u, v, a, cost, visited);
  cost[v] = -1;
  int mx = -1;
  int p = -1;
  for (int i = 0; i < n; i++) {
    if (cost[i] < cost_v[i]) {
      if (mx < cost[i]) {
        mx = cost[i];
        p = i;
      }
    }
  }
  while (cost_v[p] - cost[p] > 2) {
    cost[p] += 2;
  }
  if (cost_v[p] - cost[p] == 2) cost[p]++;
  cout << cost[p] << endl;
  return 0;
}
