import java.io.*;
import java.util.*;

public class dwarfs_nn {

    static List<Integer>[] edges;

    static void solve() throws IOException {
        int n = nextInt();
        edges = new List[n];
        for (int i = 0; i < n; i++) {
            edges[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i + 1 < n; i++) {
            int v = nextInt() - 1;
            int u = nextInt() - 1;
            edges[v].add(u);
            edges[u].add(v);
        }
        int v1 = nextInt() - 1;
        int v2 = nextInt() - 1;
        dp = new int[n];
        parent = new int[n];
        dfs(v1, -1);
        int[] path = new int[n];
        int pathLen = 0;
        for (int i = v2; i >= 0; i = parent[i]) {
            path[pathLen++] = i;
        }
        path = Arrays.copyOf(path, pathLen);
        int[] maxPath = new int[pathLen];
        maxPath[0] = dp[path[0]];
        for (int i = 1; i < pathLen; i++) {
            int v = path[i];
            int maxPathDown = 0;
            for (int j : edges[v]) {
                if (parent[v] != j && path[i - 1] != j) {
                    maxPathDown = Math.max(maxPathDown, dp[j]);
                }
            }
            maxPath[i] = Math.max(maxPath[i - 1], maxPathDown + i + 1);
        }
        int maxPathFromRoot = 0;
        int ans = 0;
        for (int i = pathLen - 1; i > 0; i--) {
            maxPathFromRoot = Math.max(maxPathFromRoot, pathLen - i);
            int v = path[i];
            for (int j : edges[v]) {
                if (parent[v] != j && path[i - 1] != j) {
                    maxPathFromRoot = Math.max(maxPathFromRoot, dp[j] + pathLen - i);
                }
            }
            ans = Math.max(ans, Math.min(maxPathFromRoot, maxPath[i - 1]));
        }
        out.println(ans);
    }

    static int[] parent;
    static int[] dp;

    static void dfs(int v, int p) {
        parent[v] = p;
        dp[v] = 1;
        for (int i : edges[v]) {
            if (i == p) {
                continue;
            }
            dfs(i, v);
            dp[v] = Math.max(dp[v], dp[i] + 1);
        }
    }

    static StringTokenizer tokenizer;
    static BufferedReader reader;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new FileReader("dwarfs.in"));
        out = new PrintWriter("dwarfs.out");
        solve();
        out.close();
        reader.close();
    }

    static String next() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            String line = reader.readLine();
            if (line == null) {
                return null;
            }
            tokenizer = new StringTokenizer(line);
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

}
