#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
struct edge {
  int to;
  long long cost;
  edge(int to, long long cost) : to(to), cost(cost) {}
};
vector<vector<edge> > G;
vector<bool> vis;
vector<long long> D;
vector<int> leaves;
int N, u, v;
class LCA {
 public:
  int V, logV;
  vector<int> depth, len;
  vector<vector<int> > parent;
  LCA(int V) {
    this->V = V;
    logV = 0;
    while (V > (1LL << logV)) logV++;
    this->depth = vector<int>(V);
    this->len = vector<int>(V);
    this->parent = vector<vector<int> >(logV, vector<int>(V));
  }
  void init(int v, int par, int d, int l) {
    depth[v] = d;
    parent[0][v] = par;
    len[v] = l;
    for (int i = 0; i < (int)G[v].size(); i++) {
      int w = G[v][i].to;
      int lc = G[v][i].cost;
      if (w == par) continue;
      init(w, v, d + 1, lc + l);
    }
  }
  void build() {
    for (int k = 0; k + 1 < logV; k++) {
      for (int 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]];
      }
    }
  }
  int query(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < logV; k++) {
      if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = logV - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
void dfs(int tmp, int par, long long cost) {
  if (!vis[tmp]) {
    if (par != -1) {
      D[tmp] = D[par] + cost;
    }
    vis[tmp] = true;
    for (auto ne : G[tmp]) dfs(ne.to, tmp, ne.cost);
    if (G[tmp].size() - 1 == 0) leaves.push_back(tmp);
  }
}
int main() {
  cin >> N >> u >> v;
  u--;
  v--;
  G = vector<vector<edge> >(N);
  vis = vector<bool>(N);
  D = vector<long long>(N);
  vector<int> A(N - 1), B(N - 1);
  for (int i = (int)(0); i < (int)(N - 1); i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    G[A[i]].push_back(edge(B[i], 1));
    G[B[i]].push_back(edge(A[i], 1));
  }
  LCA lca(N);
  lca.init(0, -1, 0, 0);
  lca.build();
  D[v] = 0;
  dfs(v, -1, 0);
  long long ans = 0;
  for (int l : leaves) {
    if (l == v) continue;
    int m = l;
    int z = lca.query(u, m);
    if (2 * D[z] - D[u] >= 0) {
      ans = max(D[m] - 1, ans);
    }
  }
  cout << ans << endl;
  return 0;
}
