#include <bits/stdc++.h>
using ll = long long;
const ll infll = 1e18;
using namespace std;
const int maxn = 2e5;
vector<int> g[maxn];
int dist1[maxn];
int dist2[maxn];
int p1[maxn];
int p2[maxn];
struct Solution {
  Solution() {
    int n, tak, aoki;
    cin >> n >> tak >> aoki;
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    queue<int> q;
    q.push(aoki);
    memset(dist1, 63, sizeof(dist1));
    memset(dist2, 63, sizeof(dist2));
    int inf = dist2[0];
    dist1[aoki] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto u : g[v]) {
        if (dist1[u] > dist1[v] + 1) {
          dist1[u] = dist1[v] + 1;
          p1[u] = v;
          q.push(u);
        }
      }
    }
    vector<int> path;
    int fin = tak;
    while (fin != aoki) {
      path.push_back(fin);
      fin = p1[fin];
    }
    path.push_back(aoki);
    reverse(path.begin(), path.end());
    int gg = path[((int)path.size() - 3) / 2];
    set<int> forbidden;
    for (int i = ((int)path.size() - 3) / 2 + 1; i < path.size(); i++) {
      forbidden.insert(path[i]);
    }
    q.push(gg);
    dist2[gg] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto u : g[v]) {
        if (dist2[u] > dist2[v] + 1 && forbidden.find(u) == forbidden.end()) {
          dist2[u] = dist2[v] + 1;
          q.push(u);
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (dist2[i] != inf) {
        ans = max(ans, dist2[i]);
      }
    }
    cout << ans / 2 + ((int)path.size() - 2);
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (; t; t--) {
    Solution s;
  }
  return 0;
}
