#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int ans = 0;
vector<int> tree[100001];
void dfs1(int now, int depth, vector<int> &dist) {
  dist[now] = depth;
  for (auto x : tree[now]) {
    if (dist[x] == -1) dfs1(x, depth + 1, dist);
  }
  return;
}
void dfs2(int now, int depth, vector<int> &distt, vector<int> &dista) {
  ans = max(ans, depth);
  dista[now] = depth;
  for (auto x : tree[now]) {
    if (dista[x] == -1 && distt[x] > depth + 1)
      dfs2(x, depth + 1, distt, dista);
  }
}
int main() {
  int n, u, v;
  vector<int> dist1(100001);
  vector<int> dist2(100001);
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  for (int i = 0; i <= 100000; i++) {
    dist1[i] = -1;
    dist2[i] = -1;
  }
  dfs1(v, 0, dist1);
  dfs2(u, 0, dist1, dist2);
  cout << ans << endl;
  return 0;
}
