#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
template <class T>
inline void chmin(T& a, T b) {
  a = min(a, b);
}
template <class T>
inline void chmax(T& a, T b) {
  a = max(a, b);
}
void input();
void solve();
void daminput();
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}
int N;
int U, V;
vector<int> A, B;
void input() {
  cin >> N;
  cin >> U >> V;
  A.resize(N - 1);
  B.resize(N - 1);
  for (int n = 0; n < N - 1; n++) {
    cin >> A[n] >> B[n];
  }
}
void daminput() {}
template <class T>
struct Gedge {
  int src, to;
  T cost;
  int id;
  Gedge(int s, int t, T c, int i = -1) : src(s), to(t), cost(c), id(i) {}
  Gedge(int t, T c) : src(-1), to(t), cost(c), id(-1) {}
};
template <class T>
using WeightedGraph = vector<vector<Gedge<T>>>;
using UnweightedGraph = vector<vector<long long>>;
template <class T>
using Gedges = vector<Gedge<T>>;
template <class T>
struct TNode {
  int parent;
  vector<int> childs;
  T cost;
  int id;
  TNode() : parent(-1), cost(0), id(-1){};
};
template <class T>
using Tree = vector<TNode<T>>;
template <class T>
void doublingConstruct(Tree<T>& tree, vector<vector<int>>& doubling) {
  int N = tree.size();
  doubling.push_back(vector<int>(N, -1));
  for (int n = 0; n < N; n++) {
    doubling[0][n] = tree[n].parent;
  }
  vector<int> res(N, -1);
  while (true) {
    bool flag = false;
    vector<int>& d = doubling.back();
    for (int n = 0; n < N; n++) {
      if (d[n] != -1) {
        res[n] = d[d[n]];
        flag = true;
      } else
        res[n] = -1;
    }
    if (!flag) return;
    doubling.push_back(res);
  }
}
template <class T>
void setDepth(int root, Tree<T>& tree, vector<int>& depth) {
  int N = tree.size();
  depth.resize(N, 0);
  queue<int> q;
  q.push(root);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int d = depth[cur];
    for (int ch : tree[cur].childs) {
      depth[ch] = d + 1;
      q.push(ch);
    }
  }
}
template <class T>
int goRoot(Tree<T>& tree, vector<vector<int>>& doubling, int v, int time) {
  int N = tree.size();
  for (int t = 0; t < doubling.size() && v != -1; t++) {
    if ((time & (1 << t))) {
      v = doubling[t][v];
    }
  }
  return v;
}
template <class T>
int LCA(Tree<T>& tree, vector<vector<int>>& doubling, vector<int>& depth, int u,
        int v) {
  if (u == v) return u;
  if (depth[u] > depth[v]) swap(u, v);
  v = goRoot(tree, doubling, v, depth[v] - depth[u]);
  int s = -1, e = N;
  while (e - s > 1) {
    int m = (e + s) / 2;
    if (goRoot(tree, doubling, u, m) != goRoot(tree, doubling, v, m))
      s = m;
    else
      e = m;
  }
  return goRoot(tree, doubling, u, e);
}
template <class Type>
void SetTree(WeightedGraph<Type>& G, Tree<Type>& T, int root = 0) {
  int N = G.size();
  T.resize(N);
  queue<int> q;
  q.push(root);
  T[root].parent = -1;
  T[root].id = -1;
  T[root].cost = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (Gedge<Type>& e : G[cur]) {
      if (e.to == T[cur].parent) continue;
      T[e.to].parent = cur;
      T[cur].childs.push_back(e.to);
      T[e.to].id = e.id;
      T[e.to].cost = e.cost;
      q.push(e.to);
    }
  }
}
Tree<int> T;
vector<int> depth;
vector<vector<int>> doubling;
vector<int> DDP;
int ddp(int u) {
  if (DDP[u] != -1) return DDP[u];
  DDP[u] = depth[u];
  for (int ch : T[u].childs) {
    chmax(DDP[u], ddp(ch));
  }
  return DDP[u];
}
void solve() {
  WeightedGraph<int> G(N);
  for (int n = 0; n < N - 1; n++) {
    G[A[n] - 1].push_back({B[n] - 1, 1});
    G[B[n] - 1].push_back({A[n] - 1, 1});
  }
  SetTree(G, T, V - 1);
  setDepth(V - 1, T, depth);
  doublingConstruct(T, doubling);
  int dU = depth[U - 1];
  int ans = 0;
  DDP.resize(N, -1);
  vector<int> ord(N);
  for (int n = 0; n < N; n++) {
    ord[n] = n;
    DDP[n] = depth[n];
  }
  sort(ord.begin(), ord.end(),
       [&](int a, int b) { return depth[a] > depth[b]; });
  for (int n = 0; n < N; n++) {
    int cur = ord[n];
    if (T[cur].parent != -1) {
      chmax(DDP[T[cur].parent], DDP[cur]);
    }
  }
  for (int p = 0; p < N; p++) {
    int dp = depth[p];
    if (dU - dp >= (dU % 2 == 0 ? dU : dU + 1) / 2) {
      chmax(ans, (dU % 2 == 0 ? dU : dU - 1) / 2);
      continue;
    }
    int temp = dU - dp;
    int dq = ddp(p);
    temp += dq - dp;
    int I = dU + dq - 2 * dp;
    int k0 = ((dq - I) % 2 == 0 ? dq - I : dq - I - 1) / 2;
    int k1 = ((dq - I - 2) % 2 == 0 ? dq - I - 2 : dq - I - 1) / 2;
    temp += min(2 * k0, 2 * k1 + 1);
    chmax(ans, temp);
  }
  cout << ans << "\n";
}
