#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
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 << endl;
    else
      cout << " ";
  }
}
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>>;
map<int, int> mp, mpinv;
int num = 1;
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];
  }
};
template <typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(g.size(), INF);
  using Pi = pair<T, int>;
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if (dist[idx] < cost) continue;
    for (auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if (dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}
void dfs(int now, int prev, const WeightedGraph<int> &tr,
         UnWeightedGraph &tr2) {
  for (int i = 0; i < (int)(tr[now].size()); ++i) {
    int nxt = tr[now][i];
    if (nxt == prev) continue;
    if (mp[now] == 0) {
      mp[now] = num;
      mpinv[num] = now;
      num++;
    }
    if (mp[nxt] == 0) {
      mp[nxt] = num;
      mpinv[num] = nxt;
      num++;
    }
    tr2[mp[now] - 1].push_back(mp[nxt] - 1);
    dfs(nxt, now, tr, tr2);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  WeightedGraph<int> tr(n);
  vi dim(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    dim[a]++;
    dim[b]++;
    tr[a].emplace_back(edge<int>(a, b, 1));
    tr[b].emplace_back(edge<int>(b, a, 1));
  }
  UnWeightedGraph tr2(n);
  dfs(u, -1, tr, tr2);
  vi leaf;
  for (int i = 0; i < n; ++i) {
    if (dim[i] == 1) leaf.push_back(i);
  }
  DoublingLowestCommonAncestor<UnWeightedGraph> lca(tr2);
  lca.build();
  vi taka = dijkstra<int>(tr, u);
  vi ao = dijkstra<int>(tr, v);
  int ma = taka[v] - 1;
  for (int i = 0; i < (int)(leaf.size()); ++i) {
    if (leaf[i] == u || leaf[i] == v) continue;
    int now = lca.query(mp[v] - 1, mp[leaf[i]] - 1);
    if (now != 0) {
      now = mpinv[now] - 1;
      if (taka[now] >= ao[now]) continue;
    }
    ma = max(ma, ao[leaf[i]] - 1);
  }
  cout << ma << endl;
}
