#include <bits/stdc++.h>
using namespace std;
const int LG = 18;
long long up[100005][LG], tin[200005], tout[100005], CLK = 1, lvl[100005];
vector<int> v[100005];
void dfspre(int u, int dad, int depth) {
  tin[u] = CLK++;
  lvl[u] = depth;
  up[u][0] = dad;
  for (int i = 1; i < LG; ++i) up[u][i] = up[up[u][i - 1]][i - 1];
  for (auto i : v[u])
    if (i != dad) dfspre(i, u, depth + 1);
  tout[u] = CLK++;
}
bool is_ancestor(int x, int y) {
  return tin[x] <= tin[y] && tout[y] <= tout[x];
}
int lca(int x, int y) {
  if (is_ancestor(x, y)) return x;
  if (is_ancestor(y, x)) return y;
  for (int i = LG; i--;) {
    if (!is_ancestor(up[x][i], y)) x = up[x][i];
  }
  return up[x][0];
}
int dist(int x, int y) { return lvl[x] + lvl[y] - 2 * lvl[lca(x, y)]; }
int x, y, RES;
void dfs(int u, int dad) {
  if (dist(u, y) <= dist(u, x)) {
    RES = max(RES, dist(u, x) - !dist(x, y));
    return;
  }
  int child = 0;
  for (auto i : v[u])
    if (i != dad) {
      dfs(i, u);
      ++child;
    }
  if (!child) {
    RES = max(RES, max(-10, dist(u, y)) - 0 * (dist(u, y) % 2));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n >> x >> y;
  for (int x, y, i = n; --i;) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfspre(x, x, 0);
  dfs(x, 0);
  if (dist(x, y) % 2) --RES;
  cout << RES << endl;
}
