#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;
int n, a, b;
vector<int> g[N];
int d1[N], d2[N];
int ans;

void dfs1(int v, int p = -1) {
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    d1[to] = d1[v] + 1;
    dfs1(to, v);
  }
}

void dfs2(int v, int p = -1) {
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    d2[to] = d2[v] + 1;
    dfs2(to, v);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> n >> a >> b;
  --a, --b;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  dfs1(a), dfs2(b);
  for (int i = 0; i < n; ++i) {
    if (d1[i] <= d2[i]) {
      ans = max(ans, d2[i] - 1);
    }
  }
  cout << ans;

  return 0;
}