#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>>& anc, vector<vector<pair<int, int>>>& G,
         vector<int>& depth, vector<long long>& dist, int i, int p = -1) {
  for (pair<int, int>& e : G[i])
    if (e.first != p) {
      anc[e.first].push_back(i);
      depth[e.first] = depth[i] + 1;
      dist[e.first] = dist[i] + e.second;
      dfs(anc, G, depth, dist, e.first, i);
    }
}
void init(vector<vector<int>>& anc, vector<vector<pair<int, int>>>& G,
          vector<int>& depth, vector<long long>& dist, int k) {
  depth[k] = 0;
  dist[k] = 0;
  dfs(anc, G, depth, dist, k);
  int n = anc.size();
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < n; ++j) {
      if (anc[j].size() < i + 1 || anc[anc[j][i]].size() < i + 1) continue;
      anc[j].push_back(anc[anc[j][i]][i]);
    }
  }
}
int lca(vector<vector<int>>& anc, vector<int>& depth, vector<long long>& dist,
        int i, int j) {
  if (depth[i] > depth[j]) swap(i, j);
  while (depth[i] < depth[j]) {
    for (int k = anc[j].size() - 1; k >= 0; --k)
      if (depth[anc[j][k]] >= depth[i]) {
        j = anc[j][k];
        break;
      }
  }
  while (i != j) {
    for (int k = anc[i].size() - 1; k >= 0; --k) {
      if (anc[i][k] != anc[j][k]) {
        i = anc[i][k];
        j = anc[j][k];
        break;
      } else if (k == 0) {
        i = j = anc[i][0];
      }
    }
  }
  return i;
}
int calc_dist(vector<vector<int>>& anc, vector<int>& depth,
              vector<long long>& dist, int i, int j) {
  return dist[i] + dist[j] - dist[lca(anc, depth, dist, i, j)] * 2;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> anc(n);
  vector<vector<pair<int, int>>> edges(n);
  vector<int> depth(n);
  vector<long long> dist(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(pair<int, int>(b, 1));
    edges[b].push_back(pair<int, int>(a, 1));
  }
  init(anc, edges, depth, dist, v);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a = calc_dist(anc, depth, dist, u, lca(anc, depth, dist, u, i)),
        b = dist[i];
    int ret = calc_dist(anc, depth, dist, v, i);
    if (edges[i].size() == 1) ret--;
    if (a < b) ans = max(ans, ret);
  }
  cout << ans << endl;
}
