#include <bits/stdc++.h>
std::vector<std::vector<long long int>> G;
const long long int MAX_V = 112345;
const long long int MAX_LOG_V = 50;
class LCA {
 private:
  long long int root = 1;
  std::vector<std::vector<long long int>> parent;
  std::vector<long long int> depth;

 public:
  void dfs(long long int v, long long int p, long long int d) {
    parent[0][v] = p;
    depth[v] = d;
    for (auto i : G[v]) {
      if (i != p) dfs(i, v, d + 1);
    }
  }
  void init(long long int V) {
    parent.resize(MAX_LOG_V, std::vector<long long int>(V + 1));
    depth.resize(V + 1);
    dfs(root, -1, 0);
    for (long long int k = 0; k < MAX_LOG_V - 1; ++k) {
      for (long long int v = 1; 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 int lca(long long int u, long long int v) {
    if (depth[u] > depth[v]) std::swap(u, v);
    for (long long int 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 int 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 int dist(long long int u, long long int v) {
    long long int t = lca(u, v);
    return depth[u] + depth[v] - 2 * depth[t];
  }
};
int main() {
  long long int N, u, v;
  std::cin >> N >> u >> v;
  std::vector<long long int> A(N - 1), B(N - 1);
  for (long long int i = 0; i < N - 1; ++i) std::cin >> A[i] >> B[i];
  std::vector<long long int> leaves;
  G.resize(N + 1);
  for (long long int i = 0; i < N - 1; ++i) {
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  for (long long int i = 1; i <= N; ++i) {
    if (G[i].size() == 1) leaves.push_back(i);
  }
  long long int ans = 0;
  LCA tree;
  tree.init(N);
  for (long long int t : leaves) {
    long long int dist_u = tree.dist(t, u);
    long long int dist_v = tree.dist(t, v);
    if (dist_u >= dist_v) {
      long long int dist_uv = tree.dist(u, v);
      ans = std::max(ans, dist_uv / 2);
    } else {
      ans = std::max(ans, dist_v - (dist_v - dist_u) + (dist_v - dist_u) / 2);
    }
  }
  std::cout << ans << std::endl;
}
