#include <bits/stdc++.h>
using namespace std;
template <class C>
void min_self(C &a, C b) {
  a = min(a, b);
}
template <class C>
void max_self(C &a, C b) {
  a = max(a, b);
}
long long mod(long long n, long long m = 1000000007) {
  n %= m, n += m, n %= m;
  return n;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
unordered_map<long long, int, custom_hash> safe_map;
const int MAXN = 1e5 + 5;
const int LOGN = 18;
const long long INF = 1e14;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<int> gr[MAXN];
bool vis[MAXN];
int lca[MAXN][LOGN];
int par[MAXN], height[MAXN], depth[MAXN];
void dfs(int node, int pr) {
  vis[node] = 1;
  if (pr != -1) {
    par[node] = pr;
    height[node] = height[pr] + 1;
  }
  for (auto next : gr[node]) {
    if (!vis[next]) {
      dfs(next, node);
    }
  }
}
void calc_depth(int node, int pr) {
  if (pr != -1 && gr[node].size() == 1) {
    depth[node] = 1;
  }
  int mx = 0;
  for (auto next : gr[node]) {
    if (next == pr) continue;
    calc_depth(next, node);
    mx = max(mx, depth[next]);
  }
  depth[node] = mx + 1;
}
int up(int u, int h) {
  int mul = 0;
  while (h) {
    if (h & 1) {
      u = lca[u][mul];
    }
    mul++;
    h /= 2;
  }
  return u;
}
int find_lca(int u, int v) {
  int h1 = height[u], h2 = height[v];
  if (h1 > h2) {
    u = up(u, h1 - h2);
    h1 = h2;
  }
  if (h2 > h1) {
    v = up(v, h2 - h1);
    h2 = h1;
  }
  if (u == v) return u;
  int lo = 0, hi = h1, mid, ans = 0;
  while (lo <= hi) {
    mid = lo + (hi - lo) / 2;
    int a = up(u, mid), b = up(v, mid);
    if (a == b) {
      ans = a;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  a--, b--;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  height[0] = 0;
  dfs(0, -1);
  calc_depth(0, -1);
  par[0] = 0;
  for (int i = 0; i < n; i++) lca[i][0] = par[i];
  for (int i = 1; i < LOGN; i++) {
    for (int j = 0; j < n; j++) {
      lca[j][i] = lca[lca[j][i - 1]][i - 1];
    }
  }
  int p = find_lca(a, b);
  int ha = height[a], hb = height[b], hp = height[p];
  int ans = 0;
  if (hb - hp < ha - hp) {
    ans += hb - hp;
    a = up(a, hb - hp);
    b = up(b, hb - hp);
    ha = height[a], hb = height[b];
    int more = (ha - hb - 1) / 2;
    ans += more;
    a = up(a, more);
    if ((ha - hb) % 2 == 0) {
      ans += depth[a];
    } else {
      ans += depth[a] - 1;
    }
  } else if (hb - hp == ha - hp) {
    ans += (hb - hp - 1);
    a = up(a, hb - hp - 1);
    b = up(b, hb - hp - 1);
    ans += depth[a];
  } else {
    ans += ha;
    a = up(a, ha);
    b = up(b, ha);
    int diff = height[b] - height[a];
    int x = up(b, height[b] - 1);
    int mx = 0;
    for (auto y : gr[0]) {
      if (y != x) {
        mx = max(mx, depth[y]);
      }
    }
    if (mx == 0) {
      ;
    } else {
      ans += mx - 1;
      int more = (diff - 1) / 2;
      ans += more;
      if (diff % 2 == 0) {
        ans += more;
      } else {
        ans += more - 1;
      }
    }
  }
  cout << ans, cout << "\n";
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
