#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1 << 29;
const long long INFL = 1LL << 60;
const long long mod = 998244353;
vector<int> g[100005];
int c[100005];
int d[100005];
void dfs(int p, int i) {
  c[p] = i;
  for (int j : g[p]) {
    if (c[j] == 0) {
      dfs(j, i + 1);
    }
  }
}
void dfs1(int p, int i) {
  d[p] = i;
  for (int j : g[p]) {
    if (d[j] == 0) {
      dfs1(j, i + 1);
    }
  }
}
int ans = 0;
void dfs2(int p, int aa, int i) {
  if (c[p] == d[p]) ans = max(ans, i - 1);
  if (c[p] >= d[p]) return;
  if (c[p] + 1 == d[p]) ans = max(ans, c[p] - 1);
  for (int j : g[p]) {
    if (aa == j) continue;
    dfs2(j, p, i + 1);
  }
}
int main() {
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  for (long long i = 0; i < long long(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(u, 1);
  dfs1(v, 1);
  dfs2(u, -1, 1);
  cout << ans << endl;
}
