#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
struct edge {
  long long int to;
  long long int cost;
};
vector<vector<edge>> G;
int N, u, v;
vector<bool> aflag;
vector<int> dist1, dist2;
void dfs1(int pos) {
  if (pos == v) return;
  aflag[pos] = true;
  for (int i = 0; i < G[pos].size(); i++) {
    if (aflag[G[pos][i].to]) continue;
    dfs1(G[pos][i].to);
  }
}
void dfs2(int pos, int depth) {
  dist1[pos] = depth;
  for (int i = 0; i < G[pos].size(); i++) {
    if (dist1[G[pos][i].to] != -1) continue;
    dfs2(G[pos][i].to, depth + 1);
  }
}
void dfs3(int pos, int depth) {
  dist2[pos] = depth;
  for (int i = 0; i < G[pos].size(); i++) {
    if (dist2[G[pos][i].to] != -1) continue;
    dfs2(G[pos][i].to, depth + 1);
  }
}
int main() {
  cin >> N >> u >> v;
  G = vector<vector<edge>>(N + 1);
  aflag = vector<bool>(N + 1, false);
  dist1 = dist2 = vector<int>(N + 1, -1);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }
  dfs1(u);
  dfs2(v, 0), dfs3(u, 0);
  int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    if (dist1[i] >= dist2[i]) {
      ans = max(ans, dist1[i] - 1);
    }
  }
  cout << ans << endl;
}
