#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 1e5 + 10;
int dep[N];
vector<int> e[N];
int fa[N];
void dfs(int u) {
  dep[u] = dep[fa[u]] + 1;
  for (auto v : e[u])
    if (v != fa[u]) {
      fa[v] = u;
      dfs(v);
    }
}
int f[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, t, s;
  cin >> n >> t >> s;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }
  dfs(s);
  queue<int> q;
  q.emplace(t);
  f[t] = 1;
  for (; !q.empty(); q.pop()) {
    int u = q.front();
    for (auto v : e[u]) {
      if (dep[v] - 1 >= f[u] && !f[v]) {
        f[v] = f[u] + 1;
        if (dep[v] - 1 > f[u]) q.emplace(v);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (f[i]) {
      int x = dep[i] - (dep[i] % 2 != f[i] % 2);
      if (dep[i] == x && f[fa[i]] == dep[fa[i]]) x -= 2;
      ans = max(ans, x);
    }
  cout << --ans;
}
