#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  int u, v; cin >> u >> v;
  --u, --v;

  vvi edge(N, vi());
  int d[N][N];

  rep(i, N) rep(j, N) d[i][j] = 1e9;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
    d[a][b] = 1;
    d[b][a] = 1;
  }

  rep(k, N) rep(i, N) rep(j, N)
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  int ans = 0;
  rep(i, N) {
    if (d[u][v] == d[u][i] + d[v][i] && d[u][i] <= d[v][i]) {
      // iが中継点
      int tmp = 0;
      int end = i;
      rep(j, N) {
        if (j == v || j == i)
          continue;
        if (d[u][v] < d[u][j] + d[v][j])
          if (chmax(tmp, d[i][j]))
            end = j;
      }
      if ((d[v][end] - (d[u][i] + d[i][end])) % 2 == 0) {
        chmax(ans, d[v][end]-1);
      } else
        chmax(ans, d[v][end]-1);
    }
  }
  cout << ans << "\n";

  return 0;
}
