// thank you, 19-minute version of "lady madonna" by the rose hill junior high school jazz ensemble, for giving me something to listen to a few times while i wrote this here internet code
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
typedef long long ll;
const int N = 2e5 + 10;
const int LOG = 20;
vector<int> f[N], g[N];
int n, X, Y;
int dist[N];
int dist2[N];
int pred[LOG][N];
bool saved[N];
int ans = 0;

void dfs0(int a, int from) {
    for (auto b : g[a]) {
        if (b == from) continue;
        dist[b] = dist[a] + 1;
        pred[0][b] = a;
        dfs0(b, a);
    }
}

int getDistance(int a, int b) {
    //cout << a << "/" << b << endl;
    int res = dist[a] + dist[b];
    if (dist[a] < dist[b]) swap(a, b);
    int log = LOG - 1;
    while (log >= 0) {
        if (pred[log][a] == -1 || dist[pred[log][a]] < dist[b]) {
            log--;
        } else {
            a = pred[log][a];
        }
    }
    //cout << "-> " << a << " " << b << endl;
    if (a == b) {
        res -= 2 * dist[a];
        return res;
    }
    log = LOG - 1;
    while (log >= 0) {
        assert(a != b);
        if (pred[log][a] == pred[log][b]) {
            log--;
        } else {
            a = pred[log][a];
            b = pred[log][b];
        }
    }
    res -= 2 * dist[pred[0][a]];
    return res;
}

void dfs1(int a, int from) {
    for (auto b : f[a]) {
        if (b == from) continue;
        dist2[b] = dist2[a] + 1;
        dfs1(b, a);
    }
}

void dfs2(int a, int from, int t) {
    if (dist[a] <= t) return;
    if (saved[a]) {
        cout << -1 << endl;
        exit(0);
    }
    ans = max(ans, dist[a]);
    for (auto b : f[a]) {
        if (b == from) continue;
        dfs2(b, a, t + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> X >> Y;
    X--, Y--;
    vector<pair<int, int>> ev;
    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        f[x - 1].push_back(y - 1);
        f[y - 1].push_back(x - 1);
        ev.push_back({x - 1, y - 1});
    }
    
    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        g[x - 1].push_back(y - 1);
        g[y - 1].push_back(x - 1);
        
    }
    dist[Y] = 0;
    pred[0][Y] = -1;
    dfs0(Y, -1);
    
    dist2[X] = 0;
    dfs1(X, -1);
    
    rep(l, 1, LOG) {
        rep(i, 0, N) {
            if (pred[l - 1][i] == -1) pred[l][i] = -1;
            else pred[l][i] = pred[l - 1][pred[l - 1][i]];
        }
    }
    
    //rep(i, 0, n) cout << pred[0][i] << " / " << dist2[i] << endl;
    
    for (auto e : ev) {
        //cout << e.first << "/" << e.second << ": " << getDistance(e.first, e.second) << endl;
        if (getDistance(e.first, e.second) > 2) {
            for (auto x : {e.first, e.second}) {
                /*if (dist2[x] < dist[x]) {
                    cout << -1 << endl;
                    exit(0);
                }*/
                saved[x] = true;
            }
        }
    }
    
    dfs2(X, -1, 0);
    cout << (ans) * 2 << endl;
    
    return 0;
}


Measured memory_bytes: 49648