/**

     .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW / BESITE SOV
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o

*/


//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


bool DEBUG = 0;
#define debug(x) if (DEBUG) {cerr << #x << " = " << x << "\n";}
#define debug_vec(x) if (DEBUG) {cerr << #x << " = {"; for(auto a : x) cerr << a << ","; cerr << "}" << endl;}

//#define int ll

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, d[N], a, b, tin[N], tout[N], timer, ans, d2[N], t[N];
vector <int> g[N];
void dfs(int v, int pr) {
    tin[v] = ++timer;
    for (int to : g[v]) {
        if (to != pr) {
            d[to] = d[v] + 1;
            dfs(to, v);
        }
    }
    tout[v] = timer;
}
void dfs2(int v, int pr) {
    for (int to : g[v]) {
        if (to != pr) {
            d2[to] = d2[v] + 1;
            dfs2(to, v);
        }
    }
}
bool upper(int a, int b) {
    return (tin[a] <= tin[b] and tout[b] <= tout[a]);
}
void upd(int pos, int val) {
    for (int i = pos; i <= timer + 100; i = (i | (i + 1))) t[i] += val;
}
int get(int pos) {
    int res = 0;
    for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res += t[i];
    return res;
}
main() {
    file("sort");
    ios;
    cin >> n >> a >> b;;
    fo(i, 1, n - 1, 1) {
        int u, v;
        cin >> u >> v;
        g[u].eb(v);
        g[v].eb(u);
    }
    dfs(a, a);
    dfs2(b, b);
    fo(i, 1, n, 1) if (d[i] >= d2[i]) upd(tin[i] + 1, 1), upd(tout[i] + 1, -1);
    fo(i, 1, n, 1) {
        int val = get(tin[i]);
        if (!val and i != b) chmax(ans, d[i] + d2[i] - d[i] - 1);
    }
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 11520