#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
int N;
set<int> edge[200000];
int ans;
int u, v;
void DFS2(int x, int dis) {
  while (!edge[x].empty()) {
    int y = *edge[x].begin();
    edge[x].erase(y);
    edge[y].erase(x);
    ans = max(ans, dis + 1);
    DFS2(y, dis + 1);
  }
}
void DFS(int x, int dis) {
  if (edge[x].find(u) != edge[x].end()) {
    edge[x].erase(u);
    edge[u].erase(x);
    ans = max(ans, dis + 1);
    DFS2(u, dis + 1);
    return;
  }
  while (!edge[x].empty()) {
    int y = *edge[x].begin();
    edge[x].erase(y);
    edge[y].erase(x);
    ans = max(ans, dis + 1);
    DFS(y, dis + 1);
  }
}
int main(void) {
  cin >> N >> u >> v;
  u--, v--;
  for (int(i) = 0; (i) < (N - 1); (i)++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    edge[x].insert(y);
    edge[y].insert(x);
  }
  DFS(v, 0);
  cout << ans - 1 << "\n";
}
