#include <bits/stdc++.h>
using namespace std;
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;
}
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int M_V = 100001;
const int logV = 21;
vector<int> G[M_V];
int parent[logV][M_V];
int depth[M_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, int root) {
  dfs(root, -1, 0);
  for (int k = 0; k < logV - 1; 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 < logV; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (int k = logV - 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 n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  init(n, 0);
  vector<int> x(n, 0), y(n, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    x[i] = depth[u] + depth[i] - 2 * depth[lca(u, i)] + 1;
    y[i] = depth[v] + depth[i] - 2 * depth[lca(v, i)] + 1;
    ans = max(ans, y[i] - 2);
  }
  cout << ans << endl;
  return 0;
}
