#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const long long mod = 1000000007;
const long long N = 300005;
const long long inf = 10000000000000000;
void print(vector<long long> v) {
  long long i;
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
vector<long long> read(long long n) {
  long long i;
  vector<long long> arr(n, 0);
  for (i = 0; i < n; i++) cin >> arr[i];
  return arr;
}
vector<long long> read(long long n, long long k) {
  long long i;
  vector<long long> arr(n + k, 0);
  for (i = k; i < n + k; i++) cin >> arr[i];
  return arr;
}
bool isEven(long long n) { return n % 2 == 0; }
bool isOdd(long long n) { return n % 2 != 0; }
void solve() {
  long long t;
  cin >> (t);
  while (t--) {
    long long i, j, k, n, m, p, q, x, y, a, b, l, r;
  }
}
vector<long long> adj[N];
vector<bool> vis(N, 0);
vector<long long> tDistance(N, 0);
vector<long long> aDistance(N, 0);
vector<long long> leafDepth(N, 0);
long long t, a, n;
void dfsFill1(long long cur) {
  vis[cur] = 1;
  for (auto next : adj[cur]) {
    if (!vis[next]) {
      tDistance[next] = tDistance[cur] + 1;
      dfsFill1(next);
    }
  }
}
void dfsFill2(long long cur) {
  vis[cur] = 1;
  for (auto next : adj[cur]) {
    if (!vis[next]) {
      aDistance[next] = aDistance[cur] + 1;
      dfsFill2(next);
    }
  }
}
long long dfsDepth(long long cur) {
  vis[cur] = 1;
  bool isLeaf = 1;
  long long dep = 0;
  for (auto next : adj[cur]) {
    if (!vis[next]) {
      isLeaf = 0;
      dep = max(dep, dfsDepth(next));
    }
  }
  if (isLeaf) {
    leafDepth[cur] = 0;
    return 1;
  } else {
    leafDepth[cur] = dep;
    return leafDepth[cur] + 1;
  }
}
bool cmp(long long fir, long long sec) {
  if (leafDepth[fir] != leafDepth[sec]) {
    return (leafDepth[fir] > leafDepth[sec]);
  }
  return (aDistance[fir] > aDistance[sec]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto start = high_resolution_clock::now();
  long long i, j, k, m, p, q, x, y, b, l, r;
  cin >> n >> t >> a;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfsFill1(t);
  for (i = 0; i < n + 1; i++) {
    vis[i] = 0;
  }
  dfsFill2(a);
  for (i = 0; i < n + 1; i++) {
    vis[i] = 0;
  }
  dfsDepth(1);
  vector<long long> vertex;
  for (i = 1; i < n + 1; i++) {
    if (aDistance[i] > tDistance[i]) vertex.push_back(i);
  }
  if (vertex.empty()) {
    if (find(adj[a].begin(), adj[a].end(), t) != adj[a].end()) {
      cout << 0 << "\n";
    } else {
      cout << 1 << "\n";
    }
    return 0;
  }
  if (n == 2) {
    cout << 0 << "\n";
    return 0;
  }
  sort(vertex.begin(), vertex.end(), cmp);
  cout << aDistance[vertex[0]] + (leafDepth[vertex[0]] - 1);
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  return 0;
}
