#include <bits/stdc++.h>
using namespace std;
#define N 200001
#define M 21
vector<int> ex[N], ey[N];
void init(int n, vector<int>* e) {
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d%d", &u, &v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
}
int fx[N], fy[N][M], dx[N], dy[N];
void dfsx(int u) {
    for (auto v : ex[u]) {
        if (v == fx[u]) continue;
        fx[v] = u, dx[v] = dx[u] + 1;
        dfsx(v);
    }
}
void dfsy(int u) {
    for (auto v : ey[u]) {
        if (v == fy[u][0]) continue;
        fy[v][0] = u, dy[v] = dy[u] + 1;
        for (int i = 1; i < M; i++) fy[v][i] = fy[fy[v][i - 1]][i - 1];
        dfsy(v);
    }
}
int lca(int u, int v) {
    if (dy[u] < dy[v]) swap(u, v);
    for (int i = M - 1; ~i; i--)
        if (dy[fy[u][i]] >= dy[v]) u = fy[u][i];
    if (u == v) return u;
    for (int i = M - 1; ~i; i--)
        if (fy[u][i] != fy[v][i]) u = fy[u][i], v = fy[v][i];
    return fy[u][0];
}
int main() {
    int n, addx, addy;
    scanf("%d%d%d", &n, &addx, &addy);
    init(n, ex);
    init(n, ey);
    dfsx(addx);
    dfsy(addy);
    queue<int> que;
    que.push(addx);
    int ans = 0;
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        if (dx[u] >= dy[u]) continue;
        if (~ans) ans = max(ans, dy[u] << 1);
        for (auto v : ex[u]) {
            if (v == fx[u]) continue;
            if (dy[v] + dy[u] - 2 * dy[lca(u, v)] > 2) ans = -1;
            que.push(v);
        }
    }
    printf("%d\n", ans);
    return 0;
}