#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> node(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  stack<int> st;
  st.push(u);
  vector<bool> visited(n + 1, false);
  visited[u] = true;
  while (st.size() > 0) {
    int now = st.top();
    if (now == v) {
      break;
    }
    bool nothing = true;
    for (int i = 0; i < node[now].size(); i++) {
      int next = node[now][i];
      if (visited[next] == true) continue;
      st.push(next);
      visited[next] = true;
      nothing = false;
      break;
    }
    if (nothing == true) {
      st.pop();
    }
  }
  vector<int> path;
  while (st.size() > 0) {
    path.push_back(st.top());
    st.pop();
  }
  vector<bool> visited2(n + 1, false);
  int pathi = 0;
  for (; pathi < (path.size() + 1) / 2; pathi++) {
    visited2[path[pathi]] = true;
  }
  int start = path[pathi];
  int maxnode = start;
  queue<int> q;
  vector<int> distance(n + 1);
  distance[start] = 0;
  q.push(start);
  visited2[start] = true;
  while (q.size() > 0) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < node[now].size(); i++) {
      int next = node[now][i];
      if (visited2[next] == true) continue;
      distance[next] = distance[now] + 1;
      visited2[next] = true;
      q.push(next);
      if (distance[next] > distance[maxnode]) {
        maxnode = next;
      }
    }
  }
  int ans = pathi + distance[maxnode] - 1;
  cout << ans << endl;
  return 0;
}
