#include <bits/stdc++.h>
using namespace std;
int N, u, v;
vector<vector<int>> links, children;
vector<int> parent, depth, visit;
pair<int, int> max_depth;
void input() {
  cin >> N >> u >> v;
  u--;
  v--;
  links = vector<vector<int>>(N);
  for (int i = 0; i < (int)(N - 1); i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    links[A].push_back(B);
    links[B].push_back(A);
  }
}
void make_tree(int num, int p, int d) {
  if (d > max_depth.first) max_depth = make_pair(d, num);
  parent[num] = p;
  depth[num] = d;
  visit[num] = 1;
  for (int i : links[num]) {
    if (visit[i]) continue;
    children[num].push_back(i);
    make_tree(i, num, d + 1);
  }
}
void max_depth_under_u(int num) {
  if (depth[num] > max_depth.first) max_depth.first = depth[num];
  for (int i : children[num]) max_depth_under_u(i);
}
int main() {
  input();
  children = vector<vector<int>>(N);
  parent = depth = visit = vector<int>(N);
  max_depth = make_pair(0, v);
  make_tree(v, v, 0);
  int x = max_depth.second;
  unordered_set<int> max_root{x};
  while (x != v) {
    x = parent[x];
    max_root.insert(x);
  }
  if ((max_root.count(u)) || (max_depth.first == depth[u])) {
    cout << max_depth.first - 1 << endl;
    return 0;
  }
  x = parent[u];
  while (!max_root.count(x)) x = parent[x];
  if (depth[x] > depth[u] - depth[x]) {
    cout << max_depth.first - 1 << endl;
    return 0;
  }
  max_depth.first = depth[u];
  max_depth_under_u(u);
  cout << max_depth.first - 1 << endl;
}
