#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl; 
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//globals
ll const mod = 1e9+7;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

// CODE STARTS HERE
int time_tom[size_1d];
int time_jerry[size_1d];
std::vector<std::vector<int>> v(size_1d);
void get_leaves(int a,int b,std::vector<int> &s){
  if(v[a].size() == 1){
    s.pb(a);
  }
  for(auto &m : v[a]){
    if(m != b){
      get_leaves(m,a,s);
    }
  }
}
void dfs_tom(int a,int b,int time1){
  time_tom[a] = time1;
  for(auto &m : v[a]){
    if(m != b){
      dfs_tom(m,a,time1+1);
    }
  }
}
void dfs_jerry(int a,int b,int time1){
  time_jerry[a] = time1;
  for(auto &m : v[a]){
    if(m != b){
      dfs_jerry(m,a,time1+1);
    }
  }
}
int main(){
  IOS
  int n,x,p;cin >> n >> x >> p;
  for (int i = 0; i < n-1; ++i)
  {
    int a,b;cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  std::vector<int> s;
  get_leaves(p,0,s);
  dfs_tom(p,0,0);
  dfs_jerry(x,0,0);
  int ans = time_tom[x] - 1;
  // watch(ans)
  for(auto &m : s){
    // watch(m)
    // cout << time_tom[m] << " " << time_jerry[m] << endl;
    if(time_tom[m] > time_jerry[m]){
        if((time_tom[m] - time_jerry[m])%2 == 0)
            ans = max(time_tom[m] - 1,ans);
        else
            ans = max(time_tom[m]-1,ans);
    }   
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 34048