#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<long long> > g(n);
  for (int i = 0; i < ((int)n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bool visited[n];
  for (int i = 0; i < ((int)n); i++) visited[i] = false;
  queue<pair<long long, long long> > que;
  que.push(pair<long long, long long>(v, 0));
  visited[v] = true;
  vector<long long> dist(n, 0);
  long long cur;
  while (!que.empty()) {
    pair<long long, long long> now = que.front();
    que.pop();
    for (long long i = 0; i < g[now.first].size(); i++) {
      long long next = g[now.first][i];
      if (visited[next]) continue;
      visited[next] = true;
      dist[next] = now.second + 1;
      que.push(pair<long long, long long>(next, now.second + 1));
    }
  }
  for (int i = 0; i < ((int)n); i++) visited[i] = false;
  que.push(pair<long long, long long>(dist[u], 0));
  visited[u] = true;
  pair<long long, long long> ans = pair<long long, long long>(dist[u], 0);
  while (!que.empty()) {
    pair<long long, long long> now = que.front();
    que.pop();
    for (long long i = 0; i < g[now.first].size(); i++) {
      long long next = g[now.first][i];
      if (visited[next] || dist[next] < now.second) continue;
      visited[next] = true;
      if (ans.first < dist[next]) {
        ans.first = dist[next];
        ans.second = now.second + 1;
      }
      que.push(pair<long long, long long>(next, now.second + 1));
    }
  }
  cout << ans.first - 1 << endl;
}
