#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
int tvisit[100001], avisit[100001];
int parent[100001];
bool leaf[100001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, u, v;
  cin >> n >> u >> v;
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  queue<int> bfs;
  bfs.push(v);
  parent[v] = 0;
  while (!bfs.empty()) {
    int x = bfs.front();
    bfs.pop();
    leaf[x] = true;
    for (int y : adj[x]) {
      if (y == parent[x]) continue;
      leaf[x] = false;
      parent[y] = x;
      bfs.push(y);
    }
  }
  queue<int> qt, qa;
  qt.push(u);
  qa.push(v);
  int mx = -1;
  while (!qt.empty() && !qa.empty()) {
    int s = qt.size();
    for (int i = 0; i < s; i++) {
      int cur = qt.front();
      qt.pop();
      if (cur == v || avisit[cur]) continue;
      for (int next : adj[cur]) {
        if (tvisit[next]) continue;
        tvisit[next] = tvisit[cur] + 1;
        if (next == v || avisit[next]) {
          mx = max(mx, avisit[next]);
          continue;
        }
        qt.push(next);
      }
    }
    int s2 = qa.size();
    for (int i = 0; i < s2; i++) {
      int cur = qa.front();
      qa.pop();
      for (int next : adj[cur]) {
        if (avisit[next]) continue;
        avisit[next] = avisit[cur] + 1;
        if (tvisit[next] == avisit[next]) {
          mx = max(mx, avisit[next]);
        } else if (leaf[next] && (tvisit[next] || next == u)) {
          mx = max(mx, avisit[next] - 1);
        }
        qa.push(next);
      }
    }
  }
  cout << mx;
}
