#include <bits/stdc++.h>
using namespace std;
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];
  }
};
void bfs(int s, vector<vector<int>> &G, vector<int> &dist) {
  fill((dist).begin(), (dist).end(), -1);
  queue<int> q;
  q.push(s);
  dist[s] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto nv : G[v]) {
      if (dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      q.push(nv);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  UnWeightedGraph g(n);
  vector<vector<int>> G(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int> udist(n);
  bfs(u, G, udist);
  vector<int> vdist(n);
  bfs(v, G, vdist);
  vector<pair<int, int>> longest(n);
  for (int i = 0; i < n; i++) {
    longest[i] = make_pair(vdist[i], i);
  }
  sort((longest).begin(), (longest).end());
  reverse((longest).begin(), (longest).end());
  DoublingLowestCommonAncestor<UnWeightedGraph> lca(g);
  lca.build();
  for (int i = 0; i < n; i++) {
    int ndist = longest[i].first;
    int nu = longest[i].second;
    int root = lca.query(nu, v);
    if (udist[root] < vdist[root]) {
      cout << ndist - 1 << endl;
      return 0;
    }
  }
  cout << longest[0].first - 1 << endl;
}
