import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto u = s[1] - 1;
    auto v = s[2] - 1;
    auto G = new int[][](N);
    foreach (i; 0..N-1) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    auto d = new int[](N);
    auto b = new bool[](N);
    auto dd = new int[](N);

    void dfs3(int n, int p, int v) {
        dd[n] = v;
        foreach (m; G[n]) if (m != p) {
            dfs3(m, n, v+1);
        }
    }

    bool dfs2(int n, int p) {
        if (n == u) return b[n] = true;
        foreach (m; G[n]) if (p != m) {
            if (dfs2(m, n)) return b[n] = true;
        }
        return false;
    }

    int dfs(int n, int p) {
        foreach (m; G[n]) if (m != p) {
            if (p == -1 && !b[m] ) continue;
            d[n] = max(d[n], dfs(m, n) + 1);
        }
        return d[n];
    }

    dfs3(v, -1, 0);
    dfs2(v, -1);
    dfs(v, -1);

    int dist = dd[u] / 2 - (1 - dd[u] % 2);
    int ans = 0;

    foreach (i; 0..N) if (b[i] && dd[u] - dd[i] <= dist) {
        int turn = (dd[u] - dd[i]);
        int hoge = (dd[i] - turn) % 2;
        int val = d[i] + dd[u] - dd[i];
        val = hoge ? val :  val + 1;
        ans = max(ans, val);
    }

    ans.writeln;
}