#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> v[maxn];
int dis[maxn], vis[maxn];
int bfs(int n, int a, int b) {
  memset(dis, 0, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  queue<int> qa;
  queue<int> qb;
  qa.push(a);
  qb.push(b);
  vis[b] = 1;
  dis[a] = 0;
  int ans = 0;
  while (!qa.empty() && !qb.empty()) {
    int t = qa.size();
    int cur;
    for (int i = 0; i < t; i++) {
      cur = qa.front();
      qa.pop();
      if (vis[cur] == 0) {
        for (int j = 0; j < v[cur].size(); j++) {
          int tmp = v[cur][j];
          if (vis[tmp] == 0 && tmp != b) {
            dis[tmp] = dis[cur] + 1;
            qa.push(tmp);
          }
        }
      }
    }
    t = qb.size();
    for (int i = 0; i < t; i++) {
      cur = qb.front();
      qb.pop();
      for (int j = 0; j < v[cur].size(); j++) {
        int tmp = v[cur][j];
        if (vis[tmp] == 0) {
          qb.push(tmp);
          ans = max(ans, dis[tmp]);
          vis[tmp] = 1;
        }
      }
    }
  }
  return ans;
}
int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cout << bfs(n, a, b) << endl;
  return 0;
}
