#include <bits/stdc++.h>
using namespace std;
void dfs(int u, int goal, const vector<vector<int>> &g, vector<int> &vis,
         vector<int> &path) {
  vis[u] = 1;
  if (u == goal) {
    path.push_back(u);
    return;
  }
  for (int v : g[u]) {
    if (!vis[v]) {
      dfs(v, goal, g, vis, path);
      if (!path.empty()) {
        path.push_back(u);
        return;
      }
    }
  }
}
int dfs_depth(int u, const vector<vector<int>> &g, vector<int> &vis) {
  vis[u] = 1;
  int mx_depth = 1;
  for (int v : g[u]) {
    if (!vis[v]) {
      mx_depth = max(mx_depth, dfs_depth(v, g, vis) + 1);
    }
  }
  return mx_depth;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  vector<vector<int>> g(N);
  for (int i = 0; i < N - 1; ++i) {
    int A, B;
    cin >> A >> B;
    g[A - 1].push_back(B - 1);
    g[B - 1].push_back(A - 1);
  }
  vector<int> vis(N, 0), path_u_v;
  dfs(u, v, g, vis, path_u_v);
  reverse(begin(path_u_v), end(path_u_v));
  int len = path_u_v.size(), num_init_moves = 0;
  int begin_u = u, begin_v = v;
  for (int i = 0, j = len - 1; i + 1 <= j - 1; ++i, --j) {
    begin_u = path_u_v[i + 1];
    begin_v = path_u_v[j - 1];
    ++num_init_moves;
  }
  int mx_depth = 0;
  if (begin_v != begin_u) {
    vis.assign(N, 0);
    vis[begin_v] = 1;
    mx_depth = dfs_depth(begin_u, g, vis) - 1;
  }
  cout << mx_depth + num_init_moves << "\n";
  return 0;
}
