#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int U, V;
int dist_max, d1, d2;
struct node {
  vector<int> to;
  int dist;
  bool find;
  node() {
    dist = 0;
    find = false;
  }
};
void dfs1(int v, int p, vector<node> &nodes) {
  for (int i = 0; i < nodes[v].to.size(); i++) {
    int v_to = nodes[v].to[i];
    if (v_to == p) continue;
    nodes[v_to].dist = nodes[v].dist + 1;
    if (v_to == U) nodes[v_to].find = true;
    dfs1(v_to, v, nodes);
    if (nodes[v_to].find) nodes[v].find = true;
  }
  for (int i = 0; i < nodes[v].to.size(); i++) {
    int v_to = nodes[v].to[i];
    if (v_to == p) continue;
    nodes[v].dist = max(nodes[v].dist, nodes[v_to].dist);
  }
}
void dfs2(int v, int p, vector<node> &nodes) {
  for (int i = 0; i < nodes[v].to.size(); i++) {
    int v_to = nodes[v].to[i];
    if (v_to == p) continue;
    if (!nodes[v_to].find) continue;
    if (nodes[v_to].dist != dist_max) continue;
    d1++;
    dfs2(v_to, v, nodes);
  }
}
int main() {
  int N;
  cin >> N;
  cin >> U >> V;
  U--;
  V--;
  vector<node> nodes(N);
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    nodes[A].to.push_back(B);
    nodes[B].to.push_back(A);
  }
  dfs1(V, -1, nodes);
  dist_max = 0, d1 = 0;
  for (int v : nodes[V].to) {
    if (nodes[v].find) {
      dist_max = nodes[v].dist;
      break;
    }
  }
  dfs2(V, -1, nodes);
  d2 = nodes[U].dist - d1;
  int ans = 0;
  if (d2 < d1) {
    ans = dist_max - 1;
  } else {
    ans = d1 + d2 - 1;
  }
  cout << ans << endl;
}
