#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1LL << 60;
const int INF = 1 << 30;
long long MOD = 1000000007;
vector<long long> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<long long> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
void pres(double A, long long x = 10) {
  cout << fixed << setprecision(x) << A << endl;
}
void BinarySay(long long x, long long y = 60) {
  for (long long i = 0; i < (y); i++) cout << (x >> (y - 1 - i) & 1);
  cout << endl;
}
long long cnt_bit(long long x) { return __builtin_popcountll(x); }
long long pow_long(long long x, long long k) {
  long long res = 1;
  while (k > 0) {
    if (k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
long long pow_mod(long long x, long long k) {
  long long res = 1;
  while (k > 0) {
    if (k % 2) {
      res *= x;
      res %= MOD;
    }
    x *= x;
    x %= MOD;
    k /= 2;
  }
  return res;
}
long long inverse(long long x) { return pow_mod(x, MOD - 2); };
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; };
const long long MAX_V = 200010;
const long long MAX_LOG_V = 30;
vector<long long> G[MAX_V];
long long root = 0;
long long parent[MAX_LOG_V][MAX_V];
long long depth[MAX_V];
void dfs_lca(long long v, long long p, long long d) {
  parent[0][v] = p;
  depth[v] = d;
  for (long long to : G[v]) {
    if (to == p) continue;
    dfs_lca(to, v, d + 1);
  }
}
void init_lca(long long V = 200009) {
  dfs_lca(root, -1, 0);
  for (long long k = 0; k + 1 < MAX_LOG_V; k++) {
    for (long long v = 0; v < V; v++) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}
long long lca(long long u, long long v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (long long k = 0; k < MAX_LOG_V; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (long long k = MAX_LOG_V - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
long long N;
long long u, v;
vector<pair<long long, long long>> dist;
void dfs(long long now, long long from, long long id) {
  for (long long to : G[now]) {
    if (to == from) continue;
    if (id == 1) {
      dist[to].first = dist[now].first + 1;
    }
    if (id == 2) {
      dist[to].second = dist[now].second + 1;
    }
    dfs(to, now, id);
  }
}
long long dfs2(long long now) {
  long long res = dist[now].second;
  for (long long to : G[now]) {
    if (dist[to].second < dist[now].second) continue;
    res = max(res, dfs2(to));
  }
  return res;
}
void solve() {
  cin >> N;
  cin >> u >> v;
  u--, v--;
  root = v;
  for (long long i = 0; i < (N - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dist.resize(N);
  dist[u].first = 0;
  dfs(u, -1, 1);
  dist[v].second = 0;
  dfs(v, -1, 2);
  vector<long long> samedfs;
  for (long long i = 0; i < (N); i++) {
    if (dist[i].second == dist[u].second) {
      samedfs.push_back(i);
    }
  }
  init_lca();
  vector<long long> pos;
  for (long long i = 0; i < (samedfs.size()); i++) {
    long long LCA = lca(samedfs[i], u);
    if (dist[LCA].second - dist[u].second < dist[LCA].second) {
      pos.push_back(samedfs[i]);
    }
  }
  long long ans = 0;
  for (long long x : pos) {
    ans = max(ans, dfs2(x) - 1);
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
