#include <bits/stdc++.h>
using namespace std;
vector<int> dist1;
vector<int> dist2;
vector<vector<int>> to;
vector<bool> done;
void dfs1(int id, int d) {
  dist1[id] = d;
  done[id] = true;
  for (int i = 0; i < to[id].size(); i++) {
    int nx = to[id][i];
    if (done[nx]) continue;
    dfs1(nx, d + 1);
  }
}
void dfs2(int id, int d) {
  dist2[id] = d;
  for (int i = 0; i < to[id].size(); i++) {
    int nx = to[id][i];
    if (dist1[nx] <= d + 1) continue;
    dfs2(nx, d + 1);
  }
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  to = vector<vector<int>>(n);
  dist1 = vector<int>(n, 1000000007);
  dist2 = vector<int>(n, 1000000007);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dist1[v] = 0;
  done = vector<bool>(n, false);
  dfs1(v, 0);
  dist2[u] = 0;
  done = vector<bool>(n, false);
  dfs2(u, 0);
  int ans = 0;
  int id = 0;
  for (int i = 0; i < n; i++) {
    if (dist2[i] >= ans and dist2[i] != 1000000007) {
      ans = dist2[i];
      id = i;
    }
  }
  cout << dist1[id] - 1 << endl;
}
