#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int n;
vector<int> g[10005];
vector<int> dist;
void dfs(int s, int p, int d) {
  dist[s] = d;
  for (auto u : g[s]) {
    if (u == p) continue;
    dfs(u, s, d + 1);
  }
}
vector<int> calc(int s) {
  dist = vector<int>(n);
  dfs(s, -1, 0);
  return dist;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int u, v;
  cin >> n >> u >> v;
  --u, --v;
  for (int i = 0; i < (int)n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> distT, distA;
  distT = calc(u);
  distA = calc(v);
  int res = 0;
  for (int i = 0; i < (int)n; ++i) {
    if (distT[i] < distA[i]) res = max(res, distA[i] - 1);
  }
  cout << res << endl;
  return 0;
}
