#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if (a > b) a = b;
}
template <typename T>
void printv(const vector<T> &s) {
  for (int i = 0; i < (int)(s.size()); ++i) {
    cout << s[i];
    if (i != (int)(s.size()) - 1) cout << " ";
  }
  cout << "\n";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
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> >;
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];
  }
};
vector<int> p, dist;
void dfs(int now, int prev, int d, const UnWeightedGraph &g) {
  dist[now] = d;
  p[now] = prev;
  for (int i = 0; i < (int)(g[now].size()); ++i) {
    int nxt = g[now][i];
    if (nxt == prev) continue;
    dfs(nxt, now, d + 1, g);
  }
}
int dfs2(int now, int prev, int ao, const UnWeightedGraph &g) {
  if (now == ao) return -1;
  int res = 0;
  for (int i = 0; i < (int)(g[now].size()); ++i) {
    int nxt = g[now][i];
    if (nxt == prev) continue;
    chmax(res, dfs2(nxt, now, ao, g) + 1);
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  int ta, ao;
  cin >> ta >> ao;
  ta--;
  ao--;
  UnWeightedGraph g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  p.resize(n, 0);
  dist.resize(n, 0);
  dfs(ta, -1, 0, g);
  ll r = ao;
  ll mid = ao;
  for (int i = 0; i < dist[ao] - (dist[ao] - 1) / 2; ++i) {
    mid = r;
    r = p[r];
  }
  int ans = dfs2(r, -1, mid, g);
  ans += (dist[ao] - 1) / 2;
  cout << max(ans, dist[ao] / 2) << endl;
}
