#include <bits/stdc++.h>
using namespace std;
void bfs(vector<vector<int> >& edges, vector<int>& dist, int node) {
  queue<int> Q;
  vector<int> state(edges.size());
  Q.push(node);
  dist[node] = 0;
  state[node] = 1;
  while (!Q.empty()) {
    node = Q.front();
    Q.pop();
    for (int e : edges[node]) {
      if (state[e] == 0) {
        state[e] = 1;
        dist[e] = dist[node] + 1;
        Q.push(e);
      }
    }
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  vector<vector<int> > edges(N);
  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    cin >> a >> b;
    edges[--a].push_back(--b);
    edges[b].push_back(a);
  }
  vector<int> dist_u(N), dist_v(N);
  bfs(edges, dist_u, u);
  bfs(edges, dist_v, v);
  int d = 0, s = 0;
  for (int i = 0; i < N; ++i) {
    if (dist_v[i] >= dist_u[i]) {
      bool flag = false;
      for (int e : edges[i]) {
        if (dist_v[e] > dist_u[e]) {
          flag = true;
          break;
        }
      }
      if (flag && d < dist_u[i]) {
        d = dist_u[i];
        if (dist_v[i] > dist_u[i]) {
          s = dist_v[i] - dist_u[i] - 1;
        }
      }
    }
  }
  cout << d + s << endl;
}
