#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long int INF = 0x1fffffffffffffff;
const double eps = 1e-12;
string to_str(long long int x) {
  string res;
  while (x) res += ('0' + (x % 10)), x /= 10;
  reverse((res).begin(), (res).end());
  return res;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct Edge {
  int v, len;
};
vector<Edge> g[100010];
int root;
vector<int> parent[17], depth;
void DFS(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (Edge u : g[v])
    if (u.v != p) DFS(u.v, v, d + 1);
}
void init(int V) {
  for (int i = (0); i < (17); i++) parent[i].resize(V);
  depth.resize(V, -1);
  DFS(root, -1, 0);
  for (int k = (0); k < (16); 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 < (17); k++)
    if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
  if (u == v) return u;
  for (int k = (16); k > (-1); k--)
    if (parent[k][u] != parent[k][v]) u = parent[k][u], v = parent[k][v];
  return parent[0][u];
}
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  x--;
  y--;
  int cnt[100010] = {};
  for (int i = (0); i < (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    cnt[u]++;
    g[u].push_back({v, 1});
    g[v].push_back({u, 1});
  }
  root = x;
  init(n);
  int target = -1, ma = 0, ans = depth[y] - 1;
  for (int i = (0); i < (n); i++)
    if (i != x && cnt[i] == 0) {
      if (depth[lca(i, y)] * 2 < depth[y] && chmax(ma, depth[i])) target = i;
    }
  cerr << target << endl;
  if (target == -1) {
    chmax(ans, depth[y] - 1);
  } else {
    chmax(ans, depth[target] + depth[y] - 2 * depth[lca(target, y)] - 1);
  }
  printf("%d\n", ans);
  return 0;
}
