#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9;
using namespace std;
void solve();
void bfs();
void dfs();
void bin_search();
int gcd(int a, int b);
long long gcd(long long a, long long b);
int way[N], way2[N];
vector<int> edg[N];
bool V[N], vis[N], vis2[N];
int last, last_d;
void dist(int s, int d) {
  way[s] = d;
  vis[s] = true;
  if (way[s] > last_d) {
    last = s;
    last_d = way[s];
  }
  for (int x : edg[s]) {
    if (!vis[x]) {
      dist(x, d + 1);
    }
  }
}
void dist2(int s, int d) {
  way2[s] = d;
  vis2[s] = true;
  for (int x : edg[s]) {
    if (!vis2[x]) {
      dist2(x, d + 1);
    }
  }
}
void short_dis(int l) {
  V[l] = true;
  for (int x : edg[l]) {
    if (!V[x] && way[x] == way[l] - 1) {
      short_dis(x);
      break;
    }
  }
}
int main() {
  int n, i, j, u, v, a, b;
  cin >> n >> u >> v;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    edg[a].push_back(b);
    edg[b].push_back(a);
  }
  vector<bool> vis(false, n + 1);
  dist(v, 0);
  for (i = 1; i <= n; i++) {
    if (way[i] > way[u]) {
      short_dis(i);
    }
  }
  if (V[u] || way[u] == way[last]) {
    cout << way[last] - 1;
    return 0;
  }
  dist2(u, 0);
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    if (V[i] && way[i] <= way2[i]) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << way[last] - 1;
  else
    cout << way[u] - 1;
  return 0;
}
