#include <bits/stdc++.h>
using namespace std;
int n, ta, ao, ans;
vector<int> g[100005];
int dis[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> ta >> ao;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  memset(dis, -1, sizeof(dis));
  dis[ao] = 0;
  {
    queue<int> q;
    q.push(ao);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < g[x].size(); i++) {
        int &y = g[x][i];
        if (dis[y] == -1) {
          dis[y] = dis[x] + 1;
          q.push(y);
        }
      }
    }
  }
  {
    queue<pair<int, int> > q;
    q.push(make_pair(ta, 0));
    while (!q.empty()) {
      int x = q.front().first, d = q.front().second;
      q.pop();
      if (d >= dis[x]) {
        ans = max(ans, dis[x]);
        continue;
      }
      for (int i = 0; i < g[x].size(); i++) {
        int &y = g[x][i];
        q.push(make_pair(y, d + 1));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
