#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using ll = long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
void scans(string& str) {
  char c;
  str = "";
  scanf("%c", &c);
  if (c == '\n') scanf("%c", &c);
  while (c != '\n' && c != -1) {
    str += c;
    scanf("%c", &c);
  }
}
void scanc(char& str) {
  char c;
  scanf("%c", &c);
  if (c == -1) return;
  while (c == '\n') {
    scanf("%c", &c);
  }
  str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll ans = 0;
int n, u, v;
void dfs1(int now, vector<vector<int>>& graph, int count, vector<bool>& visited,
          vector<int>& aoki) {
  aoki[now] = count;
  visited[now] = true;
  for (auto aa : graph[now]) {
    if (!visited[aa]) dfs1(aa, graph, count + 1, visited, aoki);
  }
  return;
}
void dfs2(int now, vector<vector<int>>& graph, int count, vector<bool>& visited,
          vector<int>& aoki) {
  visited[now] = true;
  if (abs(aoki[now] - count) <= 1) {
    ans = max((ll)min(aoki[now], count), ans);
    if (aoki[now] == count) return;
  }
  for (auto aa : graph[now]) {
    if (!visited[aa]) dfs2(aa, graph, count + 1, visited, aoki);
  }
  return;
}
int main() {
  scanf("%d%d%d", &n, &u, &v);
  vector<vector<int>> graph(n);
  int a, b;
  for (int i = 0; i < (n - 1); ++i) {
    scanf("%d%d", &a, &b);
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
  vector<bool> visited(n);
  vector<int> aoki(n);
  dfs1(v - 1, graph, 0, visited, aoki);
  fill((visited).begin(), (visited).end(), false);
  dfs2(u - 1, graph, 0, visited, aoki);
  printf("%lld\n", ans);
  return 0;
}
