#include <bits/stdc++.h>
using namespace std;
bool compare(pair<pair<int, int>, vector<int>> a,
             pair<pair<int, int>, vector<int>> b) {
  if (a.first.first * b.first.second == a.first.second * b.first.first)
    return a.first.second > b.first.second;
  return a.first.first * b.first.second < a.first.second * b.first.first;
}
const int mod = 1e9 + 9;
const long long int inf = long long int(1e18);
long long int modexp(long long int x, long long int n) {
  if (n == 0) return 1;
  if (n % 2 == 0) return modexp((x * x) % mod, n / 2);
  return (x * modexp((x * x) % mod, n / 2)) % mod;
}
vector<int> g[100000], disu(100000, 0), disv(100000, 0);
void dfsu(int s, int p) {
  for (auto i : g[s]) {
    if (i != p) {
      disu[i] = disu[s] + 1;
      dfsu(i, s);
    }
  }
}
void dfsv(int s, int p) {
  for (auto i : g[s]) {
    if (i != p) {
      disv[i] = disv[s] + 1;
      dfsv(i, s);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v, x, y;
  cin >> n >> u >> v;
  --u;
  --v;
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfsu(u, -1);
  dfsv(v, -1);
  int ans = disv[u];
  int flag = 1;
  for (int i = 0; i < n; ++i) {
    if (disu[i] <= disv[i] + 1 and disv[i] > ans) {
      ans = disv[i];
    }
  }
  --ans;
  cout << ans << "\n";
}
