#include <bits/stdc++.h>
using namespace std;
template <typename TYPE>
void print_vec(const vector<TYPE>& v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v) {
  cout << endl;
  cout << "       ";
  for (int i = 0; i < v[0].size(); i++) cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   ";
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\x1B[31m" << v[i][j] << "   ";
    }
    cout << "\x1B[0m" << endl;
  }
}
using P = pair<int, int>;
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int>> vec(N, vector<int>());
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  vector<int> aoki(N, 0);
  {
    queue<P> qu;
    qu.push(P(v, -1));
    while (!qu.empty()) {
      int node = qu.front().first;
      int parent = qu.front().second;
      qu.pop();
      for (int i = 0; i < vec[node].size(); i++) {
        int child = vec[node][i];
        if (child == parent) continue;
        if (aoki[child] != 0) continue;
        aoki[child] = aoki[node] + 1;
        qu.push(P(child, node));
      }
    }
  }
  int ans = -1;
  vector<int> takahashi(N, 0);
  queue<P> qu;
  qu.push(P(u, -1));
  while (!qu.empty()) {
    int node = qu.front().first;
    qu.pop();
    int catch_place;
    for (int i = 0; i < vec[node].size(); i++) {
      int child = vec[node][i];
      if (aoki[child] + 1 == takahashi[node] + 1) {
        catch_place = child;
        continue;
      }
      if (aoki[child] == takahashi[node] + 1) {
        catch_place = child;
        continue;
      }
      takahashi[child] = takahashi[node] + 1;
      qu.push(P(child, node));
    }
    if (qu.empty()) ans = aoki[catch_place];
  }
  cout << ans << endl;
}
