#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <bitset>
#include <limits>
#include <numeric>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<ll, ll> pl;
typedef pair<pl, pl> ppl;
#define $1 first
#define $2 second
#define pb push_back
#define INF 0x5A5B5C5D
#define INF2 0x77777777
#define PI 3.1415926535897932
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX3(x,y,z) MAX(MAX(x,y),z)
#define MIN3(x,y,z) MIN(MIN(x,y),z)
#define MAX4(a,b,c,d) MAX(MAX3(a,b,c),d)
#define MIN4(a,b,c,d) MIN(MIN3(a,b,c),d)
#define MID(x,y,z) MIN(MAX(x,y),z)==z?MAX(MIN(x,y),z):MAX(x,y)
#define REP(i,n) for(ull (i)=0;(i)<ull(n);(i)++)
#define ALL(list) (list).begin(),(list).end()
#define PRESENT(list,x) (find(ALL(list),x)!=(list).end())
#define INPUT(cin_a) cin>>(cin_a)
#define INPUT2(cin_a,cin_b) cin>>(cin_a)>>(cin_b)
#define INPUT3(cin_a,cin_b,cin_c) cin>>(cin_a)>>(cin_b)>>(cin_c)
#define INPUT4(cin_a,cin_b,cin_c,cin_d) cin>>(cin_a)>>(cin_b)>>(cin_c)>>(cin_d)
#define DINPUT(int_a) int (int_a);INPUT(int_a)
#define DINPUT2(int_a,int_b) int (int_a),(int_b);INPUT2(int_a,int_b)
#define DINPUT3(int_a,int_b,int_c) int (int_a),(int_b),(int_c);INPUT3(int_a,int_b,int_c)
#define DINPUT4(int_a,int_b,int_c,int_d) int (int_a),(int_b),(int_c),(int_d);INPUT4(int_a,int_b,int_c,int_d)
#define TESTCASE(T) DINPUT(i_i__ai);for(int (T)=1;(T)<=i_i__ai;(T)++)
#define INIT(arr) memset((arr),0,sizeof(arr))
#define FILL(a,x) for(auto& acm_icpc:(a))acm_icpc=(x);
#define BETWEEN(x,low,high) ((x)>=(low)&&(x)<=(high))
#define countof(arr) (sizeof(arr)/sizeof((arr)[0]))
#define endl '\n'
#define PRINT(cout_x) cout<<(cout_x)<<endl
#define DEBUG(cout_x) cout<<">> "<<#cout_x<<" = "<<(cout_x)<<endl
#ifdef LOCAL_ALGO
#define READTXT freopen(TXTPATH,"r",stdin)
#define UNSYNC ios_base::sync_with_stdio(false)
#else
#define READTXT
#define UNSYNC ios_base::sync_with_stdio(false); cin.tie(nullptr)
#endif
#define TXTPATH "_input.txt"
inline ull GCD(ull a, ull b) { while (b != 0) { ull t = a % b; a = b; b = t; } return a; }
inline ull LCM(ull a, ull b) { return a * b / GCD(a, b); }
inline ull POW(ull a, ull b, ull m = ULLONG_MAX) { ull r = 1;	while (b) { if (b & 1) r = r * a % m; b >>= 1; a = a * a % m; } return r; }

int n, u, v;
vector<int> link[100005];
int maxDepth[100005];
int dist[100005];
bool visit[100005];
bool visit2[100005];
int rootOf[100005];
int answerDp[100005];

int dfs(int root) {
    visit[root] = true;
    for (int i : link[root]) {
        if (visit[i]) continue;
        rootOf[i] = root;
        dist[i] = dist[root] + 1;
        maxDepth[root] = max(maxDepth[root], dfs(i) + 1);
    }
    visit[root] = false;
    return maxDepth[root];
}

int dfs2(int root, int mv) {
    if (maxDepth[root] == 0) return 0;
    if (answerDp[root]) return answerDp[root];
    visit2[root] = true;

    for (int i : link[root]) {
        if (visit2[i]) continue;
        
        if (maxDepth[i] < maxDepth[root]) {
            answerDp[root] = max(answerDp[root], dfs2(i, mv) + 1);
        }
        else {
            answerDp[root] = max(answerDp[root], dfs2(i, mv + 1) + 1);
        }
    }

    visit2[root] = false;
    return answerDp[root];
}

int main() {
    UNSYNC; READTXT;
    INPUT3(n, u, v);

    REP(i, n) {
        DINPUT2(x, y);
        link[x].pb(y);
        link[y].pb(x);
    }

    dfs(v);

    if (maxDepth[u] == 0 && dist[u] == 1) {
        return cout << 0, 0;
    }

    int answer = maxDepth[u] + dist[u] - 1;

    int cnt = 1;
    int tu = rootOf[u];
    while (tu != v) {
        int distU = dist[u] - cnt * 2;

        if (distU <= 0)
            break;

        answer = max(answer, maxDepth[tu] + distU + cnt - 1);
        cnt++;
        tu = rootOf[tu];
    }

    return cout << answer, 0;
}

Measured memory_bytes: 10880