#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[] = {0, 0, 1, -1};
int dx[] = {
    1,
    -1,
    0,
    0,
};
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T> >;
template <typename T>
using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<int> >;
template <typename T>
using Matrix = vector<vector<T> >;
long long gcd(long long a, long long b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}
long long lcm(int a, long long b) { return a * b / gcd(a, b); }
long long power(long long a, long long b) {
  if (a == 1) return a;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
const int MAX = 1000000;
long long fact[MAX], fact_inv[MAX];
void init_fact(long long n) {
  fact[0] = 1;
  for (long long i = 0; i < n; i++)
    fact[i + 1] = fact[i] * (i + 1) % 1000000007;
  fact_inv[n] = power(fact[n], 1000000007 - 2);
  for (long long i = n - 1; i >= 0; i--)
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % 1000000007;
}
long long comb(long long n, long long r) {
  return (fact[n] * fact_inv[r]) % 1000000007 * fact_inv[n - r] % 1000000007;
}
long long perm(long long n, long long r) {
  return (fact[n] * fact_inv[n - r]) % 1000000007;
}
struct UnionFind {
  vector<long long> par;
  vector<long long> num;
  UnionFind(long long N) : par(N), num(N) {
    for (long long i = 0; i < N; i++) par[i] = i;
    for (long long i = 0; i < N; i++) num[i] = 1;
  }
  long long root(long long x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    num[ry] = num[rx] + num[ry];
  }
  bool same(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    return rx == ry;
  }
  long long size(long long x) { return num[root(x)]; }
};
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
long long get_digit_in(long long n, long long i) {
  for (long long j = 0; j < i - 1; j++) {
    n /= 10;
  }
  return n % 10;
}
long long get_digit(long long n) {
  long long rtn = 0;
  while (n > 0) {
    n /= 10;
    rtn++;
  }
  return rtn;
}
map<long long, long long> prime_factor(long long n) {
  map<long long, long long> rtn;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      rtn[i]++;
      n /= i;
    }
  }
  if (n != 1) rtn[n] = 1;
  return rtn;
}
void foreach_permutation(long long n, function<void(long long *)> f) {
  long long indexes[n];
  for (long long i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}
void recursive_comb(long long *indexes, long long s, long long rest,
                    function<void(long long *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}
void foreach_comb(long long n, long long k, function<void(long long *)> f) {
  long long indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}
void foreach_permutation(long long n, long long k,
                         function<void(long long *)> f) {
  foreach_comb(n, k, [&](long long *c_indexes) {
    foreach_permutation(k, [&](long long *p_indexes) {
      long long indexes[k];
      for (long long i = 0; i < k; i++) {
        indexes[i] = c_indexes[p_indexes[i]];
      }
      f(indexes);
    });
  });
}
void printv(vector<long long> &V) {
  for (auto e : V) cout << e << " ";
  cout << endl;
}
template <typename G>
struct DoublingLowestCommonAncestor {
  const int LOG;
  vector<int> dep;
  const G &g;
  vector<vector<int> > table;
  DoublingLowestCommonAncestor(const G &g)
      : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) {
    table.assign(LOG, vector<int>(g.size(), -1));
  }
  void dfs(int idx, int par, int d) {
    table[0][idx] = par;
    dep[idx] = d;
    for (auto &to : g[idx]) {
      if (to != par) dfs(to, idx, d + 1);
    }
  }
  void build() {
    dfs(0, -1, 0);
    for (int k = 0; k + 1 < LOG; k++) {
      for (int i = 0; i < table[k].size(); i++) {
        if (table[k][i] == -1)
          table[k + 1][i] = -1;
        else
          table[k + 1][i] = table[k][table[k][i]];
      }
    }
  }
  int query(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    for (int i = LOG - 1; i >= 0; i--) {
      if (((dep[v] - dep[u]) >> i) & 1) v = table[i][v];
    }
    if (u == v) return u;
    for (int i = LOG - 1; i >= 0; i--) {
      if (table[i][u] != table[i][v]) {
        u = table[i][u];
        v = table[i][v];
      }
    }
    return table[0][u];
  }
};
int main() {
  cout << fixed << setprecision(10);
  long long N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<long long> A(N - 1), B(N - 1);
  for (long long i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  UnWeightedGraph e(N);
  for (long long i = 0; i < N - 1; i++) {
    e[A[i]].push_back(B[i]);
    e[B[i]].push_back(A[i]);
  }
  vector<long long> depth(N, -1);
  depth[v] = 0;
  queue<long long> que;
  que.push(v);
  set<long long> leaves;
  while (!que.empty()) {
    long long n = que.front();
    que.pop();
    bool isLeaf = true;
    for (auto each : e[n]) {
      if (depth[each] >= 0) continue;
      depth[each] = depth[n] + 1;
      que.push(each);
      isLeaf = false;
    }
    if (isLeaf) leaves.insert(n);
  }
  DoublingLowestCommonAncestor<UnWeightedGraph> lca(e);
  lca.build();
  long long ans = 0;
  if (u == v) {
    cout << 0 << endl;
    return 0;
  }
  for (auto l : leaves) {
    long long n = lca.query(u, l);
    if (abs(depth[u] - depth[n]) >= depth[n] && n != u) continue;
    long long tmp = depth[l];
    tmp--;
    chmax(ans, tmp);
  }
  cout << ans << endl;
}
