#include <bits/stdc++.h>
using namespace std;
inline void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
inline void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
inline void Yay(bool b) { cout << (b ? "Yay!" : ":(") << 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_max = (LOG - 1); k < k_max; ++k) {
      for (int i = 0, i_max = (table[k].size()); i < i_max; ++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 dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[query(u, v)]; }
};
map<int, int> mp;
vector<vector<int> > makeTree(int V, int s, const vector<vector<int> > &G) {
  vector<vector<int> > Tree(V);
  queue<pair<int, int> > que;
  que.push(pair<int, int>(s, 0));
  mp[s] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int cur = p.first;
    int Tv = p.second;
    for (const int &u : G[cur]) {
      if (mp.count(u)) continue;
      int Tu;
      Tu = mp[u] = mp.size();
      que.push(pair<int, int>(u, Tu));
      Tree[Tv].push_back(Tu);
    }
  }
  return Tree;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  int V;
  cin >> V;
  int T, A;
  cin >> T >> A;
  --T, --A;
  vector<vector<int> > G(V);
  for (int i = 0, i_max = (V - 1); i < i_max; ++i) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    G[v].emplace_back(u);
    G[u].emplace_back(v);
  }
  vector<vector<int> > Tree = makeTree(V, A, G);
  DoublingLowestCommonAncestor<vector<vector<int> > > lca(Tree);
  lca.build();
  T = mp[T];
  A = mp[A];
  int ans = 0;
  for (int s = (1), s_max = (V); s < s_max; ++s) {
    int t = lca.query(s, T);
    int d1 = lca.dep[t];
    int d2 = lca.dep[T] - d1;
    if (d1 <= d2) continue;
    ans = max(ans, lca.dep[s] - 1);
  }
  cout << ans << endl;
  return 0;
}
