#include <bits/stdc++.h>
using namespace std;
struct Node {
  int i;
  vector<Node *> nodes;
  int depth = 0;
};
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  vector<Node> T(N + 1);
  for (int i = 1; i <= N; ++i) {
    T[i].i = i;
  }
  for (int i = 1; i <= N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    T[a].nodes.push_back(&T[b]);
    T[b].nodes.push_back(&T[a]);
  }
  vector<vector<Node *>> Q(N + 1);
  int u_depth, v_depth;
  for (int i = 1; i <= N; ++i) {
    if (T[i].nodes.size() == 1) {
      T[i].depth = 1;
      Q[1].push_back(&T[i]);
      if (T[i].i == u) u_depth = 1;
      if (T[i].i == v) v_depth = 1;
    }
  }
  int i;
  for (i = 2; i <= N; ++i) {
    for (int j = 0; j < Q[i - 1].size(); ++j) {
      Node *node = Q[i - 1][j];
      for (int k = 0; k < node->nodes.size(); ++k) {
        Node *n = node->nodes[k];
        if (n->depth == 0) {
          n->depth = i;
          Q[i].push_back(n);
          if (n->i == u) u_depth = i;
          if (n->i == v) v_depth = i;
        }
      }
    }
    if (Q[i].size() == 0) break;
  }
  int root_depth = i - 1;
  int root_count = Q[root_depth].size();
  if (u == v) {
    cout << 0 << endl;
  } else if (u_depth > v_depth) {
    if (root_count == 1) {
      cout << root_depth * 2 - v_depth - 1 << endl;
    } else {
      cout << root_depth * 2 - v_depth << endl;
    }
  } else {
    int x = u;
    while (T[x].depth != v_depth) {
      for (int i = 0; i < T[x].nodes.size(); ++i) {
        if (T[x].nodes[i]->depth > T[x].depth) {
          x = T[x].nodes[i]->i;
          break;
        }
      }
    }
    int y = v;
    while (x != y && T[x].depth != root_depth) {
      for (int i = 0; i < T[x].nodes.size(); ++i) {
        if (T[x].nodes[i]->depth > T[x].depth) {
          x = T[x].nodes[i]->i;
          break;
        }
      }
      for (int i = 0; i < T[y].nodes.size(); ++i) {
        if (T[y].nodes[i]->depth > T[y].depth) {
          y = T[y].nodes[i]->i;
          break;
        }
      }
    }
    if (x == y) {
      cout << T[x].depth * 2 - v_depth - 1 << endl;
    } else {
      cout << T[x].depth * 2 - v_depth << endl;
    }
  }
  return 0;
}
