#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
const long long N = 5 * (long long)1e5 + 10;
long long n;
struct log_lca {
  long long n = 0;
  vector<long long> parent, depth;
  vector<vector<long long>> adj;
  vector<vector<long long>> ancestor;
  log_lca(long long _n = 0) { init(_n); }
  void init(long long _n) {
    n = _n;
    parent.resize(n);
    depth.resize(n);
    adj.assign(n, {});
  }
  static long long largest_bit(long long x) { return 31 - __builtin_clz(x); }
  void add_edge(long long a, long long b) {
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  void dfs(long long node, long long par) {
    depth[node] = par < 0 ? 0 : depth[par] + 1;
    parent[node] = par;
    for (long long neighbor : adj[node])
      if (neighbor != par) dfs(neighbor, node);
  }
  void build() {
    dfs(0, -1);
    ancestor.assign(largest_bit(n) + 1, vector<long long>(n));
    ancestor[0] = parent;
    for (long long k = 0; k < largest_bit(n); k++)
      for (long long i = 0; i < n; i++)
        ancestor[k + 1][i] =
            ancestor[k][i] < 0 ? -1 : ancestor[k][ancestor[k][i]];
  }
  long long get_lca(long long a, long long b) const {
    if (depth[a] > depth[b]) swap(a, b);
    long long difference = depth[b] - depth[a];
    for (long long k = 0; 1 << k <= difference; k++)
      if (difference & 1 << k) b = ancestor[k][b];
    if (a == b) return a;
    assert(a != b && depth[a] == depth[b]);
    for (long long k = largest_bit(depth[a]); k >= 0; k--)
      if (ancestor[k][a] != ancestor[k][b]) {
        a = ancestor[k][a];
        b = ancestor[k][b];
      }
    assert(parent[a] == parent[b]);
    return parent[a];
  }
  long long get_dist(long long a, long long b) const {
    return depth[a] + depth[b] - 2 * depth[get_lca(a, b)];
  }
  long long get_kth_ancestor(long long v, long long k) const {
    for (long long i = 0; 1 << i <= k; i++)
      if (k & 1 << i) {
        v = ancestor[i][v];
        if (v < 0) break;
      }
    return v;
  }
  long long get_kth_node_on_path(long long a, long long b, long long k) const {
    long long anc = get_lca(a, b);
    long long first_half = depth[a] - depth[anc];
    long long second_half = depth[b] - depth[anc];
    assert(0 <= k && k <= first_half + second_half);
    if (k < first_half)
      return get_kth_ancestor(a, k);
    else
      return get_kth_ancestor(b, first_half + second_half - k);
  }
};
log_lca lca;
vector<long long> center = {-1, -1};
long long diameter = 0;
void add_to_center(long long p) {
  if (center[0] < 0) {
    center = {p, p};
    return;
  }
  long long dist0 = lca.get_dist(p, center[0]);
  long long dist1 = lca.get_dist(p, center[1]);
  if (dist0 + dist1 <= diameter) return;
  if (dist0 < dist1) {
    swap(dist0, dist1);
    swap(center[0], center[1]);
  }
  long long new_diameter = diameter / 2 + dist0;
  center[0] =
      lca.get_kth_node_on_path(center[0], p, new_diameter / 2 - diameter / 2);
  center[1] = lca.get_kth_node_on_path(center[0], p, new_diameter % 2);
  diameter = new_diameter;
}
vector<long long> vec[123456];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long u, v;
  cin >> n >> u >> v;
  --u, --v;
  lca.init(n);
  for (long long i = 0; i + 1 < n; ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
    lca.add_edge(a, b);
  }
  lca.build();
  for (long long i = 0; i < n; ++i) {
    ;
  }
  long long which = 0;
  long long dist = -inf;
  for (long long i = 0; i < n; ++i) {
    ;
    if ((long long)(vec[i].size()) == 1) {
      ;
      long long curr = lca.get_dist(v, i) - lca.get_dist(u, i);
      if (curr > dist) {
        dist = curr;
        which = i;
      }
    }
  }
  cout << lca.get_dist(v, which) - (dist % 2 == 0);
  return 0;
}
