#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<int> graph[n];
  for (int a, b; cin >> a >> b; ) {
    graph[a - 1].emplace_back(b - 1);
    graph[b - 1].emplace_back(a - 1);
  }
  int takahashi[n], aoki[n], parent[n], result = 0;
  auto bfs = [&](int start, int* distance) {
    queue<int> q;
    q.emplace(start);
    distance[start] = 0;
    vector<bool> visited(n);
    visited[start] = true;
    parent[start] = start;
    do {
      for (auto next : graph[q.front()]) {
        if (!visited[next]) {
          parent[next] = q.front();
          distance[next] = distance[q.front()] + 1;
          visited[next] = true;
          q.emplace(next);
        }
      }
      q.pop();
    } while (!q.empty());
  };
  bfs(u - 1, takahashi);
  bfs(v - 1, aoki);
  if (aoki[u - 1] != 1) {
    for (int i = 0; i < n; ++i) {
      if (takahashi[i] <= aoki[i]) {
        result = max(result, aoki[parent[parent[i]]] + 1);
      }
    }
  }
  cout << result;
  return 0;
}

#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=998244353;
const int N=2e5+5;



int main(){
    int N, u, v; cin >> N >> u >> v;
    u--, v--;
    vector<vi> G(N);
    for(int i=0; i<N-1; i++){
        int A, B; cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<vi> dist(2, vi(N, -1));
    for(int i=0; i<2; i++){
        queue<int> que;
        que.push(v+(u-v)*i);
        dist[i][v+(u-v)*i]=0;
        while(!que.empty()){
            int p=que.front();
            que.pop();
            for(auto &np : G[p]){
                if(dist[i][np] != -1) continue;
                dist[i][np]=dist[i][p]+1;
                que.push(np);
            }
        }
    }
    int res=0;
    for(int i=0; i<N; i++){
        if(dist[0][i] > dist[1][i]) res=max(res, dist[0][i]);
    }
    res--;
    cout << res << endl;
    return 0;
}