#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int long long MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int n, u, v;
vector<int> tree[100001];
int ne;
vector<int> ut(1000001, 0);
vector<int> vt(1000001, 0);
void dfs(int t, int pare, int deep, int w) {
  deep++;
  for (int i = 0; i < tree[t].size(); i++) {
    if (tree[t][i] != pare) {
      if (w == 0) {
        vt[tree[t][i]] = deep;
        dfs(tree[t][i], t, deep, w);
      } else {
        ut[tree[t][i]] = deep;
        dfs(tree[t][i], t, deep, w);
      }
    }
  }
}
int main() {
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> ao(n);
  vector<int> ta(n);
  dfs(v, -1, 0, 0);
  dfs(u, -1, 0, 1);
  int h = 0;
  int hl = 0;
  for (int i = 1; i <= n; i++) {
    if (ut[i] <= vt[i] && i != u && i != v) {
      if (hl < vt[i]) {
        h = i;
        hl = vt[i];
      }
    }
  }
  if (h == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << vt[h] - 1 << endl;
  return 0;
}
