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

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

#define all(v) v.begin(), v.end()

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

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

#define sz(v) (int)v.size()

#define inf (int)(1e9+7)

#define INF (ll)(1e18)

#define abs(x) (x >= 0 ? x : -(x))

#define ceil(a, b) a / b + !!(a % b)

template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



int n, u, v;

const int maxn = 100005;

vector<vector<int> > g(maxn);

vector<vector<int> > t(2, vector<int>(maxn, inf));

int key;

void dfs(int now) {

    for (int nxt : g[now]) {

        if (chmin(t[key][nxt], t[key][now] + 1)) {

            dfs(nxt);

        }

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    

    

    

    cin >> n >> u >> v;

    u--; v--;

    

    rep(i, n - 1) {

        int u, v;

        cin >> u >> v;

        u--; v--;

        g[u].eb(v);

        g[v].eb(u);

    }

    

    t[0][u] = 0;

    t[1][v] = 0;

    dfs(u);

    key = 1;

    dfs(v);

    int ans = 0;

    // rep(i, 2) { rep(j, n) cout << t[i][j] << " "; cout << endl; }

    rep(i, n) if (t[0][i] < t[1][i]) chmax(ans, t[1][i]);

    cout << ans - 1 << endl;

}




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

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

#define all(v) v.begin(), v.end()

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

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

#define sz(v) (int)v.size()

const int inf = 1e9 + 7;

const ll INF = 1e18;

#define abs(x) (x >= 0 ? x : -(x))

#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())

#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())

template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }

const int mod = 1000000007;

ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }



void solve();



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int T;

    // cin >> T;

    T = 1;



    while (T--) {

        solve();

    }

}





void solve() {

  int n;

  int p[2];

  cin >> n >> p[0] >> p[1];

  p[0]--; p[1]--;



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

  rep(i, n - 1) {

    int a, b;

    cin >> a >> b;

    a--; b--;

    g[a].eb(b);

    g[b].eb(a);

  }



  /*

  青木くんとぶつからない, 一番遠い葉へ向かう

  */



  vector<vector<int> > table(2, vector<int>(n, inf));



  rep(key, 2) {

    queue<int> q;

    q.push(p[key]);

    table[key][p[key]] = 0;



    while (!q.empty()) {

      int now = q.front();

      q.pop();



      for (int nxt : g[now]) {

        if (chmin(table[key][nxt], table[key][now] + 1)) {

          q.push(nxt);

        }

      }

    }

  }



  int ma = -1;

  rep(i, n) if (table[0][i] < table[1][i] && chmax(ma, table[1][i])) {



  }

  cout << ma - 1 << endl;

  // 高橋くんが葉に逃げるタイミングではつかまらない



}