#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int n, x, y;
vector<int> a[MAXN], b[MAXN];
int depA[MAXN], depB[MAXN];
int fa[MAXN][21];
void dfsA(int x, int f) {
    depA[x] = depA[f] + 1;
    for (int i = 0; i < a[x].size(); i++) {
        int u = a[x][i];
        if (u == f) continue;
        dfsA(u, x);
    }
}
void dfsB(int x, int f) {
    depB[x] = depB[f] + 1;
    fa[x][0] = f;
    for (int i = 1; i < 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (int i = 0; i < b[x].size(); i++) {
        int u = b[x][i];
        if (u == f) continue;
        dfsB(u, x);
    }
}
int lca(int u, int v) {
    if (depB[u] < depB[v]) swap(u, v);
    for (int i = 19; i >= 0; i--)
        if (depB[fa[u][i]] >= depB[v]) u = fa[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--)
        if (fa[u][i] != fa[v][i]) {
            u = fa[u][i];
            v = fa[v][i];
        }
    return fa[u][0];
}
int ans;
void dfs(int x, int f) {
    if (depA[x] >= depB[x]) return;
    if (ans != -1) ans = max(ans, (depB[x] - 1) * 2);
    for (int i = 0; i < a[x].size(); i++) {
        int u = a[x][i];
        if (u == f) continue;
        if (depB[u] + depB[x] - 2 * depB[lca(u, x)] > 2) ans = -1;
        dfs(u, x);
    }
}
int main() {
    while (SF("%d%d%d", &n, &x, &y) != EOF) {
        int u, v;
        for (int i = 1; i < n; i++) {
            SF("%d%d", &u, &v);
            a[u].push_back(v);
            a[v].push_back(u);
        }
        for (int i = 1; i < n; i++) {
            SF("%d%d", &u, &v);
            b[u].push_back(v);
            b[v].push_back(u);
        }
        dfsA(x, 0);
        dfsB(y, 0);
        ans = 0;
        dfs(x, 0);
        PF("%d\n", ans);
        for (int i = 1; i <= n; i++) {
            a[i].clear();
            b[i].clear();
        }
    }
}