#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];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  for (auto v : e[u])
    if (v != fa) dfs(v, u);
}
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, 0);
  queue<int> q;
  q.emplace(t);
  f[t] = 1;
  int ans = 1;
  for (; !q.empty(); q.pop()) {
    int u = q.front();
    for (auto v : e[u]) {
      if (f[v]) continue;
      if (dep[v] - 1 > f[u]) {
        ans = max(ans, f[v] = f[u] + 1);
        q.emplace(v);
      } else if (dep[v] - 1 == f[u])
        ans = max(ans, f[u] + 1);
    }
  }
  cout << --ans;
}
