#include <bits/stdc++.h>
const long INF = 1e9;
using namespace std;
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<long, long>;
using vi = vc<long>;
vector<long> G[100010];
long root;
long parent[15][100010];
long depth[100010];
void dfs(long v, long p, long d) {
  parent[0][v] = p;
  depth[v] = d;
  for (long i = long(0); i < long(G[v].size()); i++) {
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
  }
}
void init(long V) {
  dfs(root, -1, 0);
  for (long k = 0; k + 1 < 14; k++) {
    for (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 lca(long u, long v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (long k = long(0); k < long(14); k++) {
    if (depth[v] - depth[u] >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (long k = 13; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  long N;
  cin >> N;
  long u, v;
  cin >> u >> v;
  u--;
  v--;
  root = v;
  for (long i = long(0); i < long(N - 1); i++) {
    long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  init(N);
  long pos = depth[u];
  for (long i = long(0); i < long(N); i++) {
    if (pos < depth[i]) {
      if (depth[u] - depth[lca(u, i)] <= depth[lca(u, i)]) pos = depth[i];
    }
  }
  cout << pos - 1 << endl;
}
