#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);
constexpr int64 MOD = 1000000007;
struct Vertex {
  int level, parent;
  vint edges;
};
void DFS(vector<Vertex>& graph, int current, int parent, int level) {
  graph[current].level = level;
  graph[current].parent = parent;
  for (const int to : graph[current].edges) {
    if (graph[to].level == 0) {
      DFS(graph, to, current, level + 1);
    }
  }
}
int getLongest(vector<Vertex>& graph, int start) {
  if (graph[start].edges.size() == 1) {
    return graph[start].level;
  }
  int longest = -1;
  for (const int to : graph[start].edges) {
    if (to != graph[start].parent) {
      longest = max(longest, getLongest(graph, to));
    }
  }
  return longest;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<Vertex> graph(n);
  for (int i = 0; i < (n - 1); ++i) {
    int ai, bi;
    cin >> ai >> bi;
    --ai;
    --bi;
    graph[ai].edges.push_back(bi);
    graph[bi].edges.push_back(ai);
  }
  DFS(graph, v, -1, 1);
  vint route;
  route.push_back(u);
  for (int parent = graph[u].parent; parent != v;
       parent = graph[parent].parent) {
    route.push_back(parent);
  }
  route.push_back(v);
  int ans = -1;
  auto itT = route.begin();
  for (int i = 0; i < (route.size() / 2); ++i) {
    int currentLength = getLongest(graph, *itT) - 2;
    ans = max(ans, currentLength);
    ++itT;
  }
  cout << ans << endl;
  return 0;
}
