#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
const int maxn = (int)1e5;
vector<int> edges[maxn];
int dp[2][maxn] = {0};
bool visi[maxn] = {0};
void dfs(int v, int par, int d, int p) {
  visi[v] = true;
  dp[p][v] += d;
  for (auto x : edges[v]) {
    if (x == par) continue;
    if (!visi[x]) dfs(x, v, d + 1, p);
  }
}
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  for (long long i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(u, -1, 0, 0);
  memset(visi, 0, sizeof(visi));
  dfs(v, -1, 0, 1);
  int ans = 0;
  for (long long i = 0; i < n; ++i) {
    if (dp[0][i] >= dp[1][i]) continue;
    ans = max(ans, dp[1][i] - 1);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
