#include <bits/stdc++.h>
using namespace std;
struct LCA {
  static const int BITLEN_MAX = 31;
  vector<int> parent[BITLEN_MAX];
  vector<int> depth;
  int bitlen;
  void init(int N, const vector<vector<int>> &edges) {
    int root = 0;
    bitlen = 1;
    while ((1 << bitlen) < N) ++bitlen;
    for (int i = 0; i < bitlen; ++i) parent[i].resize(N);
    depth.resize(N, -1);
    dfs(root, -1, 0, edges);
    for (int k = 0; k + 1 < bitlen; ++k) {
      for (int v = 0; v < N; ++v) {
        if (depth[v] == -1) continue;
        if (parent[k][v] < 0) {
          parent[k + 1][v] = -1;
        } else {
          parent[k + 1][v] = parent[k][parent[k][v]];
        }
      }
    }
  }
  void dfs(int v, int p, int d, const vector<vector<int>> &edges) {
    parent[0][v] = p;
    depth[v] = d;
    for (int u : edges[v]) {
      if (u != p) dfs(u, v, d + 1, edges);
    }
  }
  int query_lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < bitlen; ++k) {
      if (((depth[v] - depth[u]) >> k) & 1) v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = bitlen - 1; k >= 0; --k) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
  int query_dist(int u, int v) {
    int l = query_lca(u, v);
    return depth[u] + depth[v] - 2 * depth[l];
  }
};
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  vector<vector<int>> edges(N, vector<int>(0));
  for (int i = 0; i + 1 < N; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  LCA lca;
  lca.init(N, edges);
  int dst = u;
  int da = 0;
  for (int k = 0; k < N; ++k) {
    if (lca.query_lca(u, v) == u && lca.query_dist(k, u) >= lca.query_lca(k, v))
      continue;
    int uklca = lca.query_lca(u, k);
    if (lca.query_dist(uklca, u) >= lca.query_dist(uklca, v)) continue;
    int ukdist = lca.query_dist(u, k);
    if (ukdist > da) {
      dst = k;
      da = ukdist;
    }
  }
  int res = lca.query_dist(v, dst) - 1;
  cout << res << '\n';
}
