#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358;
const double EPS = 1e-8;
vector<vector<int>> v;
tuple<int, int, int> bfs(int a, int b, int n) {
  int len = 0;
  queue<int> q;
  vector<int> pt;
  q.push(b);
  q.push(a);
  pt.resize(n);
  pt[a] = 1;
  pt[b] = -1;
  while (true) {
    len++;
    for (auto i : v[q.front()]) {
      if (pt[i] == pt[q.front()] * -1) {
        if (pt[q.front()] == -1)
          return make_tuple(i, q.front(), len / 2);
        else
          return make_tuple(q.front(), i, len / 2);
      }
      if (pt[i] == 0) {
        pt[i] = pt[q.front()];
        q.push(i);
      }
    }
    q.pop();
  }
}
int dfs(int x, int block) {
  int res = 0;
  for (auto i : v[x]) {
    if (i != block) res = max(res, dfs(i, x) + 1);
  }
  return res;
}
void solve() {
  int n, pa, pb, root, block, len, res;
  pair<int, int> ipt;
  cin >> n >> pa >> pb;
  v.resize(n);
  for (int i = 0; i < (n - 1); i++) {
    cin >> ipt.first >> ipt.second;
    ipt.first--;
    ipt.second--;
    v[ipt.first].emplace_back(ipt.second);
    v[ipt.second].emplace_back(ipt.first);
  }
  tie(root, block, len) = bfs(pa - 1, pb - 1, n);
  res = dfs(root, block);
  cout << len + res << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
}
