#include <bits/stdc++.h>

using namespace std;

void inf() {
    cout << "-1\n";
    exit(0);
}

int n, x, y;
vector<vector<int> > gr1, gr2;
vector<int> d, pr, d2, pr2;

void readGr(vector<vector<int> > &gr1) {
    gr1.assign(n, vector<int>());
    for (int i = 1; i < n; ++i) {
        int v1, v2;
        scanf("%d%d", &v1, &v2);
        --v1;
        --v2;
        gr1[v1].push_back(v2);
        gr1[v2].push_back(v1);
    }
}

void dfs(int v, int prv, vector<vector<int> >& gr, vector<int>& d, vector<int>& pr) {
    for (int nv : gr[v])
        if (nv != prv) {
            d[nv] = d[v] + 1;
            pr[nv] = v;
            dfs(nv, v, gr, d, pr);
        }
}

int findDst(int v1, int v2, vector<int> &d, vector<int>& pr) {
    if (d[v1] > d[v2])
        swap(v1, v2);
    if (d[v2] >= d[v1] + 3)
        return 3;
    int ans = 0;
    while (d[v2] != d[v1]) {
        ++ans;
        v2 = pr[v2];
    }
    while (ans < 3 && v1 != v2) {
        ans += 2;
        v1 = pr[v1];
        v2 = pr[v2];
    }
    return min(ans, 3);
}

int main() {
    scanf("%d%d%d", &n, &x, &y);
    --x; --y;
    readGr(gr1);
    readGr(gr2);
    
    d2.assign(n, 0);
    pr2.assign(n, -1);
    dfs(y, -1, gr2, d2, pr2);
    
    vector<int> good(n, 0);
    for (int i = 0; i < n; ++i)
        for (int v : gr1[i])
            if (i < v)
                if (findDst(i, v, d2, pr2) >= 3) {
                    good[i] = good[v] = 1;
                }
    vector<int> d(n, -1);
    queue<int> Q;
    Q.push(x);
    
    d[x] = 0;
    int ans = d2[x];
    while (!Q.empty()) {
        int v = Q.front();
        Q.pop();
        if (good[v])
            inf();
        for (int nv : gr1[v])
            if (d[nv] < 0 && d[v] + 1 < d2[nv]) {
                Q.push(nv);
                ans = max(ans, d2[nv]);
                d[nv] = d[v] + 1;
            }
            else if (d[v] + 1 == d2[nv])
                ans = max(ans, d2[nv]);
    }
    cout << 2*ans << "\n";   
    return 0;
}