#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
constexpr int N_MAX = 100000;
constexpr int INF = 1 << 30;
vector<int> graph[N_MAX];
class LowestCommonAncestor {
 public:
  int root, n, LOG_V_MAX = 30;
  vector<int> depth;
  vector<vector<int>> parent;
  LowestCommonAncestor(int root = 0, int n = N_MAX) : root(root), n(n) {
    depth.assign(n, -1);
    parent.assign(n, vector<int>(LOG_V_MAX, -1));
    dfs(root, -1, 0);
    for (int j = 1; j < LOG_V_MAX; ++j) {
      for (int i = 0; i < n; ++i) {
        if (parent[i][j - 1] == -1) continue;
        parent[i][j] = parent[parent[i][j - 1]][j - 1];
      }
    }
  }
  void dfs(int node, int par, int d) {
    depth[node] = d;
    parent[node][0] = par;
    for (int child : graph[node]) {
      int c = child;
      if (c == par) continue;
      dfs(c, node, d + 1);
    }
  }
  int get_lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    int depth_diff = depth[v] - depth[u];
    for (int j = 0; j < LOG_V_MAX; ++j) {
      if (depth_diff & (1 << j)) {
        v = parent[v][j];
      }
    }
    if (u == v) return u;
    for (int j = LOG_V_MAX - 1; j >= 0; --j) {
      if (parent[u][j] != parent[v][j]) {
        u = parent[u][j];
        v = parent[v][j];
      }
    }
    return parent[u][0];
  }
  int get_dist(int u, int v) {
    return depth[u] + depth[v] - 2 * depth[get_lca(u, v)];
  }
};
set<Pii> st;
int minimax(int takahashi, int aoki, bool takahashi_turn, int aoki_cnt,
            LowestCommonAncestor &lca) {
  if (st.find({takahashi, aoki}) != st.end()) return INF;
  st.emplace(takahashi, aoki);
  if (takahashi == aoki) {
    return aoki_cnt;
  }
  if (takahashi_turn) {
    int max_aoki_cnt = -1, argmax_node = -1;
    for (int next_node : graph[takahashi]) {
      int child_ret = minimax(next_node, aoki, false, aoki_cnt, lca);
      if (child_ret == INF) continue;
      if (max_aoki_cnt < child_ret) {
        max_aoki_cnt = child_ret;
        argmax_node = next_node;
      }
    }
    return max_aoki_cnt;
  } else {
    int min_aoki_cnt = 1 << 30, argmin_node = -1;
    for (int next_node : graph[aoki]) {
      if (lca.get_dist(takahashi, aoki) < lca.get_dist(takahashi, next_node))
        continue;
      int child_ret = minimax(takahashi, next_node, true, aoki_cnt + 1, lca);
      if (min_aoki_cnt > child_ret) {
        min_aoki_cnt = child_ret;
        argmin_node = next_node;
      }
      return min_aoki_cnt;
    }
    return min_aoki_cnt;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, takahashi, aoki, a, b;
  cin >> n >> takahashi >> aoki;
  --takahashi;
  --aoki;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  LowestCommonAncestor lca = LowestCommonAncestor();
  cout << minimax(takahashi, aoki, true, 0, lca) << endl;
}
