#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 100001;
vector<vector<int> > G = vector<vector<int> >(MAX_V, vector<int>(0, 0));
int root;
int parent[30][MAX_V];
vector<int> depth(MAX_V);
void dfs(int v, int p, int d) {
  parent[0][v] = p, depth[v] = d;
  for (int i = 0; i < G[v].size(); i++)
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
}
void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < 30; 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 lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < 30; k++)
    if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
  if (u == v) return u;
  for (int k = 30 - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
int main(int argc, char const *argv[]) {
  long long int x, y, n, a, b;
  std::cin >> n >> a >> b;
  for (long long int i = 0; i < n - 1; i++) {
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  root = 1;
  init(n + 1);
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int A = abs(depth[lca(a, i)] - depth[a]);
    long long int B = abs(depth[lca(b, i)] - depth[b]);
    long long int sa = depth[lca(a, i)] - depth[lca(b, i)];
    long long int C = B + abs(depth[lca(b, i)] - depth[i]);
    if (B + sa == A && lca(a, i) == i) ans = max(ans, A);
    if (B + sa <= A) continue;
    ans = max(ans, C - 1);
  }
  std::cout << ans << '\n';
  return 0;
}
