#include <bits/stdc++.h>
const long long INF = (long long)1e7 + 1;
const long long mod = (long long)998244353;
const long long hell = (long long)1000000007;
using namespace std;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y % 2) res = (x * res);
    x = (x * x);
    y = y / 2;
  }
  return res;
}
long long int modinv(long long int x) { return power(x, hell - 2); }
void solve();
void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fastIO();
  solve();
}
long long int pw(long long int k, long long int x);
long long int gcd(long long int x, long long int y);
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first)
    return (a.first < b.first);
  else
    return a.second < b.second;
}
vector<int> gr[100001];
vector<int> path;
unordered_set<int> ppath;
void dfs(int v, int p, int ed) {
  path.push_back(v);
  if (v == ed) return;
  for (auto u : gr[v]) {
    if (u != p) dfs(u, v, ed);
  }
  path.pop_back();
}
int calc(int v, int p) {
  int x = 0;
  for (auto u : gr[v]) {
    if (u != p and ppath.find(u) == ppath.end()) x = max(x, calc(u, v) + 1);
  }
  return x;
}
void solve() {
  int test;
  test = 1;
  while (test--) {
    int n, u, v;
    cin >> n >> u >> v;
    for (int i = 1; i < n; i++) {
      int a, b;
      cin >> a >> b;
      gr[a].push_back(b);
      gr[b].push_back(a);
    }
    dfs(v, -1, u);
    int x = path.size();
    x -= 2;
    x /= 2;
    int sz = path.size();
    for (int i = 0; i < sz; i++) ppath.insert(path[i]);
    int ans = 0;
    for (int i = sz - 1; i >= sz - x - 1; i--) {
      ans = max(ans, i + calc(path[i], -1));
    }
    cout << ans - 1;
  }
}
long long int gcd(long long int x, long long int y) {
  if (x == 0)
    return y;
  else
    return gcd(y % x, x);
}
long long int pw(long long int k, long long int x) {
  if (x == 0) return 1;
  if (x & 1)
    return ((pw(k, x - 1)) * k);
  else
    return ((pw(k, x / 2)) * (pw(k, x / 2)));
}
