#include <bits/stdc++.h>
using namespace std;
const int LOG = 22;
vector<int> G[100010];
int parent[25][100010];
int d[100010];
void dfs(int v, int p) {
  for (int x : G[v]) {
    if (x == p) continue;
    parent[0][x] = v;
    d[x] = d[v] + 1;
    dfs(x, v);
  }
}
void init(int v) {
  d[v] = 0;
  parent[0][v] = -1;
  dfs(v, -1);
  for (int k = 0; k + 1 < LOG; k++) {
    for (int i = 0; i < v; i++) {
      if (parent[k][i] < 0) {
        parent[k + 1][i] = -1;
      } else {
        parent[k + 1][i] = parent[k][parent[k][i]];
      }
    }
  }
}
int lca(int u, int v) {
  if (d[u] > d[v]) swap(u, v);
  for (int k = 0; k < LOG; k++) {
    if ((d[v] - d[u]) & (1 << k)) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (int k = LOG - 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 i, n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  init(v);
  int ans = 0;
  for (i = 0; i < n; i++) {
    int x = lca(u, i);
    if (d[x] > d[u] - d[x]) {
      ans = max(ans, d[i] - 1);
    }
  }
  if (ans == 0) {
    assert(false);
  }
  cout << ans << endl;
}
