// 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.918588214915845x):
#include <bits/stdc++.h>

using namespace std;



// エイリアス

using  ll = long signed long;

using ull = long unsigned long;

using  ld = long double;

using   P = pair<int, int>;

using llP = pair<ll, ll>;

using DoP = pair<double, double>;



// 汎用マクロ

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

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

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

#define FOREACH(i,q) for (auto &i : q)

#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)

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

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;}

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

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

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

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

const int INF = 1 << 28;

const ll INF64 = 1ll << 55;

const int mod = 1000000007;

//const int mod = 998244353;





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> dist1(n+1, INF), dist2(n+1, INF);

  queue<int> q;



  dist1[u] = 0;

  q.push(u);

  while(!q.empty()) {

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



    for(auto next : g[now]) {

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

    }

  }



  dist2[v] = 0;

  q.push(v);

  while(!q.empty()) {

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



    for(auto next : g[now]) {

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

    }

  }



  int ans = 0;

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

    if(dist1[x] >= dist2[x]) continue;

    chmax(ans, dist2[x]-1);

  }

  cout << ans << endl;

}