#include <bits/stdc++.h>
using namespace std;
vector<int64_t> g[100002];
int64_t vis[100002];
int64_t d1[100002], d2[100002];
void dfs1(int64_t u, int64_t d) {
  vis[u] = 1;
  d1[u] = d;
  for (auto x : g[u]) {
    if (vis[x] == 0) dfs1(x, d + 1);
  }
}
void dfs2(int64_t v, int64_t d) {
  vis[v] = 1;
  d2[v] = d;
  for (auto x : g[v]) {
    if (vis[x] == 0) dfs2(x, d + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int64_t n, i, u, v, a, b;
  cin >> n >> u >> v;
  for (i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (i = 1; i <= n; i++) vis[i] = 0;
  dfs1(u, 0);
  for (i = 1; i <= n; i++) vis[i] = 0;
  dfs2(v, 0);
  int64_t ans = 0;
  for (i = 1; i <= n; i++) ans = max(ans, d2[i] - d1[i]);
  cout << ans << endl;
}
