#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod2 = 998244353;
const long long INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 100005;
vector<int> G[MAX];
int dt[MAX], da[MAX];
void dfs(int u) {
  for (int v : G[u]) {
    if (dt[v] != -1) continue;
    dt[v] = dt[u] + 1;
    dfs(v);
  }
}
void dfs2(int u) {
  for (int v : G[u]) {
    if (da[v] != -1) continue;
    da[v] = da[u] + 1;
    dfs2(v);
  }
}
bool check(int u) {
  for (int v : G[u]) {
    if (da[v] > da[u]) return false;
  }
  return true;
}
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);
  }
  memset(dt, -1, sizeof(dt));
  memset(da, -1, sizeof(da));
  dt[u] = 0, da[v] = 0;
  dfs(u), dfs2(v);
  int res = -1, idx = -1;
  for (int i = 0; i < (n); ++i) {
    if (!check(i)) continue;
    if (dt[i] < da[i] && dt[i] > res) {
      res = dt[i];
      idx = i;
    }
  }
  cout << da[idx] - 1 << endl;
  return 0;
}
