#include <bits/stdc++.h>
using namespace std;
struct Node {
  std::vector<int> connects;
  int parent;
  std::vector<int> next;
  int depth;
  int maxDepth;
  int pos;
};
Node nodes[100010];
int n;
int u, v;
int root;
void makeTree(int start) {
  int curNode;
  std::queue<int> q;
  q.push(start);
  while (!q.empty()) {
    curNode = q.front();
    q.pop();
    for (int i = 0; i < nodes[curNode].connects.size(); i++) {
      int newNode = nodes[curNode].connects[i];
      if (newNode == nodes[curNode].parent) continue;
      nodes[curNode].next.push_back(newNode);
      nodes[newNode].parent = curNode;
      nodes[newNode].depth = nodes[curNode].depth + 1;
      q.push(newNode);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &u, &v);
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    nodes[a].connects.push_back(b);
    nodes[b].connects.push_back(a);
    nodes[a].maxDepth = -1;
    nodes[b].maxDepth = -1;
    nodes[a].pos = a;
    nodes[b].pos = b;
  }
  root = v;
  nodes[root].parent = -1;
  nodes[root].depth = 1;
  makeTree(root);
  for (int i = 1; i <= n; i++) {
    if (nodes[i].next.size() != 0) continue;
    int p = i;
    int curDepth = nodes[p].depth;
    while (p != -1) {
      if (nodes[p].maxDepth < curDepth) nodes[p].maxDepth = curDepth;
      p = nodes[p].parent;
    }
  }
  int pa = root;
  int pb = u;
  std::vector<int> routeAToB;
  while (pb != pa) {
    routeAToB.push_back(pb);
    pb = nodes[pb].parent;
  }
  reverse(routeAToB.begin(), routeAToB.end());
  int count = 0;
  int pNextA = 0;
  pb = u;
  while ((nodes[pb].depth - nodes[pa].depth) > 2) {
    pb = nodes[pb].parent;
    pa = routeAToB[pNextA];
    count++;
    pNextA++;
  }
  int curABDist = nodes[pb].depth - nodes[pa].depth;
  int distLeft = nodes[pb].maxDepth - nodes[pb].depth;
  count = count + distLeft;
  if (curABDist == 2) {
    count = count + 1;
  }
  printf("%d\n", count);
  return 0;
}
