#include <bits/stdc++.h>
using namespace std;
int dist[100001];
vector<int> adj[100001];
int tin[100001], tout[100001];
int t;
int ancestor[20][100001];
void dfs(int x, int p, int d) {
  tin[x] = t++;
  ancestor[0][x] = p;
  for (int i = 1; i < 20; i++)
    ancestor[i][x] = ancestor[i - 1][ancestor[i - 1][x]];
  dist[x] = d;
  for (int i = 0; i < adj[x].size(); i++)
    if (adj[x][i] != p) dfs(adj[x][i], x, d + 1);
  tout[x] = t;
}
bool is_ancestor(int x, int y) {
  if (x == 0 || y == 0) return true;
  return tin[x] <= tin[y] && tout[x] >= tout[y];
}
int lca(int x, int y) {
  if (is_ancestor(x, y)) return x;
  if (is_ancestor(y, x)) return y;
  for (int i = 19; i >= 0; i--)
    if (!is_ancestor(ancestor[i][x], y)) x = ancestor[i][x];
  return ancestor[0][x];
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  int a, b;
  t = 0;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if (u == v) {
    cout << "0\n";
    return 0;
  }
  dfs(1, 0, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int distu = dist[u] + dist[i] - 2 * dist[lca(u, i)];
    int distv = dist[v] + dist[i] - 2 * dist[lca(v, i)];
    if (distv < distu) ans = max(ans, distu - 1);
  }
  cout << ans << "\n";
  return 0;
}
