import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, U, V;
    scan(N, U, V);
    U--, V--;
    auto G = new long[][](N);
    foreach (_; 0 .. N - 1)
    {
        long A, B;
        scan(A, B);
        A--, B--;
        G[A] ~= B;
        G[B] ~= A;
    }

    if (G[U].length == 1 && G[U][0] == V)
    {
        writeln(0);
        return;
    }

    void bfs1(ref long[] leave, ref long[] dist, long v)
    {
        DList!long S;
        S.insertBack(v);
        dist[] = -1;
        dist[v] = 0;
        leave[] = true;
        while (!S.empty)
        {
            long u = S.front;
            S.removeFront;
            foreach (w; G[u])
                if (dist[w] == -1)
                {
                    dist[w] = dist[u] + 1;
                    S.insertBack(w);
                    leave[u] = false;
                }
        }
    }

    auto du = new long[](N);
    auto l = new long[](N);
    auto dv = new long[](N);
    bfs1(l, du, U);
    bfs1(l, dv, V);
    long e = V;
    foreach (w; 0 .. N)
        if (du[w] < dv[w] && dv[e] < dv[w] && l[w])
            e = w;
    // du.writeln;
    // dv.writeln;
    // writeln(e, " ", du[e], " ", dv[e]);
    writeln(dv[e] - 1);
}
