// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

using ll = long long;

using edge = struct {int to; ll cost;};



#define mod 1000000007

#define REP(i, n) for (int i = 0; i < n; i++)

#define INF (1 << 29)





//long C(long n, long r);

//long long gcd(long long a, long long b);

//long long lcm(long long a, long long b);



vector<vector<int>> tree(100001);

map<int, int> leefs;

int ans = 0;



vector<int> dis(100001);



void dfs(int v, int p, int d){

    bool isLeef = true;

    for(auto &x : tree[v]){

        if(x == p) continue;

        isLeef = false;

        dfs(x, v, d+1);

    }

    if(isLeef) leefs[v] = d;

}



void ddfs(int v, int p, int d){

    dis[v] = d;

    for(auto &x : tree[v]){

        if(x == p) continue;

        ddfs(x, v, d+1);

    }

}



void solve()

{

    int n, u, v;

    cin >> n >> u >> v;

    for(int i = 0; i < n - 1; i++){

        int a, b;

        cin >> a >> b;

        tree[a].push_back(b);

        tree[b].push_back(a);

    }

    dfs(v, -1, 0);

    ddfs(u, -1, 0);

    for(auto &x : leefs){

        if(dis[x.first] < x.second) ans = max(ans, x.second - 1);

    }

    cout << ans << "\n";

}



int main()

{

    solve();

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.918127895983975x):
#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) for (int i = 0; i < n; ++i)

#define ALL(a) (a).begin(), (a).end()

#define rALL(a) (a).rbegin(), (a).rend()

#define SZ(x) ((int)(x).size())

using ll = long long;

using ull = unsigned long long;

using P = pair<int, int>;

using llP = pair<ll, ll>;

using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};

const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};

const int INF = 1 << 28;

const ll INF64 = 1ll << 55;

const int mod = 1000000007;

//const int mod = 998244353;



template <class T>inline bool chmin(T &a, const T b)

{

  if (a > b)

  {

    a = b;

    return true;

  }

  return false;

}

template <class T>inline bool chmax(T &a, const T b)

{

  if (a < b)

  {

    a = b;

    return true;

  }

  return false;

}

template <class T>inline void line_out(const vector<T> vec) {

  int n = SZ(vec);

  rep(i, n) {

    cout << vec[i];

    if(i < n-1) cout << " ";

  }

  cout << endl;

  return;

}



struct mint

{

  ll x; // typedef long long ll;

  mint(ll x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a)

  {

    if ((x += a.x) >= mod)

      x -= mod;

    return *this;

  }

  mint &operator-=(const mint a)

  {

    if ((x += mod - a.x) >= mod)

      x -= mod;

    return *this;

  }

  mint &operator*=(const mint a)

  {

    (x *= a.x) %= mod;

    return *this;

  }

  mint operator+(const mint a) const

  {

    mint res(*this);

    return res += a;

  }

  mint operator-(const mint a) const

  {

    mint res(*this);

    return res -= a;

  }

  mint &operator++()

  {

    if ((x += 1) >= mod)

      x -= mod;

    return *this;

  }

  mint &operator--()

  {

    if ((x += mod - 1) >= mod)

      x -= mod;

    return *this;

  }

  mint operator*(const mint a) const

  {

    mint res(*this);

    return res *= a;

  }

  mint pow(ll t) const

  {

    if (!t)

      return 1;

    mint a = pow(t >> 1);

    a *= a;

    if (t & 1)

      a *= *this;

    return a;

  }



  // for prime mod

  mint inv() const

  {

    return pow(mod - 2);

  }

  mint &operator/=(const mint a)

  {

    return (*this) *= a.inv();

  }

  mint operator/(const mint a) const

  {

    mint res(*this);

    return res /= a;

  }

};





int main()

{

  int n, u, v;

  cin >> n >> u >> v;

  vector<vector<int>> g(n+1);

  rep(i, n-1) {

    int a, b; cin >> a >> b;

    g[a].push_back(b);

    g[b].push_back(a);

  }



  vector<int> taka(n+1, INF), aoki(n+1, INF);



  queue<int> q;

  auto update = [&](int now, vector<int> &dist) {

    for(auto next : g[now]) {

      if(chmin(dist[next], dist[now]+1)) q.push(next);

    }

  };



  taka[u] = 0;

  q.push(u);

  while(!q.empty()) {

    int now = q.front(); q.pop();

    update(now, taka);

  }



  aoki[v] = 0;

  q.push(v);

  while(!q.empty()) {

    int now = q.front(); q.pop();

    update(now, aoki);

  }



  int ans = 0;

  for(int i = 1; i <= n; ++i) {

    if(g[i].size() != 1 || taka[i] >= aoki[i]) continue;



    int tmp = taka[i] + (aoki[i]-taka[i])-1;

    chmax(ans, tmp);

  }



  cout << ans << endl;

}