#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int T,A,n;
  cin >> n >> T >> A;
  T--,A--;
  vector<vector<int>> v(n);
  rep(i,n-1){
    int a,b;cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  ll res = 0;
  bool is = true;
  vector<int> next(n,T);
  {
    vector<int> dt(n,-1);
    dt[T] = 0;
    queue<int> que;
    que.push(T);
    while(!que.empty()){
      int ov = que.front();que.pop();
      for(int nv : v[ov]){
        if(dt[nv] != -1)continue;
        next[nv] = ov;
        dt[nv] = dt[ov] + 1;
        que.push(nv);
      }
    }
    if(dt[A] & 1){
      int d = dt[A];
      while(dt[next[A]] >= d-d/2)A = next[A];
      T = A;
      while(dt[next[T]] >= d/2 && next[T] != T)T = next[T];
      res += d/2;
    }else{
      int d = dt[A];
      while(dt[next[A]] >= d-(d-2)/2)A = next[A];
      T = A;
      while(dt[next[T]] >= (d-2)/2 && next[T] != T)T = next[T];
      res += (d-2)/2;
      is = false;
    }
  }
  int L = -1;
  {
    for(int ov : v[T])for(int nv : v[ov])if(nv == A){
      L = ov;
      break;
    }
  }
  queue<int> que;
  que.push(T);
  vector<int> d(n,-1);
  d[T] = 0;
  while(!que.empty()){
    int ov = que.front();que.pop();
    for(int nv : v[ov]){
      if(nv == A || d[nv] != -1 || nv == L)continue;
      d[nv] = d[ov]+1;
      que.push(nv);
    }
  }
  int K = T;
  rep(i,n)if(d[i] > d[K])K = i;
  if(is)res += d[K];
  else res += d[K]+1;
  cout << res << endl;

  /*////////////
  cout << "L :" << L << endl;
  printf("T :%d A :%d\n",T+1,A+1);

  */////////////


  return 0;
}
/*
7
4 7
1 2
1 3
2 4
2 5
3 6
3 7
*/
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int N = 100005;
vector<VI> tree;
int dist1[N], dist2[N];


void dfs(int v, int d, int from, int *arr) {
    arr[v] = d;
    for (int u : tree[v]) {
        if (u == from) continue;
        dfs(u, d + 1, v, arr);
    }
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, u, v;
    cin >> n >> u >> v;
    tree.assign(n + 2, VI());
    REP(i, n - 1) {
        int x, y;
        cin >> x >> y;
        tree[x].pb(y);
        tree[y].pb(x);
    }
    dfs(u, 0, 0, dist1);
    dfs(v, 0, 0, dist2);
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        if (dist1[i] < dist2[i]) {
            mx = max(mx, dist2[i]);
        }
    }
    cout << mx - 1 << "\n";
}