//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, U, V;
vector <int> Graph[int(1e5 + 5)];
int DistT[int(1e5 + 5)], DistA[int(1e5 + 5)];

int Prepare(){
  scanf("%d%d%d", &N, &U, &V);
  fill(DistT, DistT + N + 1, -1);
  fill(DistA, DistA + N + 1, -1);
  for (int i = 0; i < N - 1; i++){
    int A, B; scanf("%d%d", &A, &B);
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  return 0;
}

int BFS(){
  queue <int> que;
  que.push(U); DistT[U] = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (DistT[next] != -1) continue;
      DistT[next] = DistT[Q] + 1;
      que.push(next);
    }
  }
  que.push(V); DistA[V] = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (DistA[next] != -1) continue;
      DistA[next] = DistA[Q] + 1;
      que.push(next);
    }
  }
  return 0;
}

int main(){
  Prepare(); BFS();

  int ans = 0;
  for (int i = 1; i <= N; i++){
    if (DistA[i] >= DistA[U] && DistT[i] < DistA[i]){
      ans = max(ans, DistA[i] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
ll power(ll x, ll y); 

const ll MOD = 1000000007;
const int MX = 1e5 + 5;

vector<int> v[MX];

void bfs(vector<int> &level, int s){
	queue<int> q;
	q.push(s);
	while(q.size()){
		auto p = q.front();
		q.pop();
		for(auto i : v[p]) if(!level[i]){
			level[i] = level[p] + 1;
			q.push(i);
		}
	}
}
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
	int n, late, early;
	cin >> n >> late >> early;
	in_edges(n - 1);
	vector<int> A(MX, 0), B(MX, 0);
	bfs(A, late);
	bfs(B, early);
	int mx = 1;
	repp(i, 1, n) if(B[i] >= A[i] && B[i] >= mx) mx = B[i];
	for(auto i : v[late]) if(i == early) mx = 1;
	cout << mx - 1;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}