#include <bits/stdc++.h>
using namespace std;
const long mod = 1e9 + 7;
const int size = 1e5;
const int inf = 1e9;
int N;
int u, v;
vector<int> g[size];
vector<pair<int, int>> dist(size);
void dfs1(int p, int s) {
  for (int k : g[s]) {
    if (k == p) continue;
    dist[k].first = dist[s].first + 1;
    dfs1(s, k);
  }
  return;
}
void dfs2(int p, int s) {
  for (int k : g[s]) {
    if (k == p) continue;
    dist[k].second = dist[s].second + 1;
    dfs2(s, k);
  }
  return;
}
int main() {
  cin >> N >> u >> v;
  u--;
  v--;
  int a, b;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dist[u].first = 0;
  dfs1(-1, u);
  dist[v].second = 0;
  dfs2(-1, v);
  deque<pair<int, int>> task;
  task.push_back({u, 0});
  int ans = 0;
  pair<int, int> p;
  int t, d;
  while (!task.empty()) {
    p = task.front();
    t = p.first;
    d = p.second;
    task.pop_front();
    for (int k : g[p.first]) {
      int temp = dist[k].second - p.second;
      if (temp >= 2)
        task.push_back({k, p.second + 1});
      else if (temp == 1) {
        ans = max(ans, p.second + 1);
      } else if (temp == 0) {
        ans = max(ans, p.second);
      }
    }
  }
  cout << ans << endl;
}
