/* be name khoda */

// #define stream_enable
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 200010;
const ll maxnlg = 19;

ll n, X, Y;
pii es_a[maxn];
vi g[2][maxn];
ll st[maxn], ft[maxn], pars[maxnlg][maxn], ht[maxn];
ll q[maxn * 2], col[maxn];
bool reach_N_move[maxn], reach[maxn];

ll tim = 0;
void dfs_lca(ll x, ll par) {
    st[x] = tim++;
    pars[0][x] = par;
    fori (i, maxnlg - 1) pars[i + 1][x] = pars[i][pars[i][x]];
    for (auto y : g[1][x]) {
        if (y != par) {
            ht[y] = ht[x] + 1;
            dfs_lca(y, x);
        }
    }
    ft[x] = tim;
}

ll LCA(ll a, ll b) {
    if (st[a] > st[b]) swap(a, b);
    if (ft[a] >= ft[b]) return a;
    forir (i, maxnlg) {
        if (ft[pars[i][a]] < ft[b]) a = pars[i][a];
    }
    return pars[0][a];
}

void MAIN() {

    cin >> n >> X >> Y; --X, --Y;
    fori (i, n - 1) {
        ll a, b; cin >> a >> b; --a, --b;
        es_a[i] = {a, b};
        g[0][a].eb(b), g[0][b].eb(a);
    }
    fori (i, n - 1) {
        ll a, b; cin >> a >> b; --a, --b;
        g[1][a].eb(b), g[1][b].eb(a);
    }
    dfs_lca(Y, Y);

    memset(col, -1, sizeof col);
    ll l = 0, r = 0;
    q[r++] = X;
    q[r++] = Y;
    reach[X] = true;
    col[X] = 0;
    col[Y] = 1;
    while (r != l) {
        ll x = q[l++];
        if (col[x] == 0) reach_N_move[x] = true;
        for (auto y : g[col[x]][x]) {
            if (col[y] == -1 || col[x] == 1 && col[y] != 1) {
                if (col[x] == 0) reach[y] = true;
                col[y] = col[x];
                q[r++] = y;
            }
        }
    }

    fori (i, n - 1) {
        ll a, b; tie(a, b) = es_a[i];
        if ((reach_N_move[a] || reach_N_move[b]) && ht[a] + ht[b] - ht[LCA(a, b)] * 2 > 2) {
            cout << "-1\n";
            return;
        }
    }
    ll ans = 0;
    fori (i, n) {
        if (reach[i]) smax(ans, ht[i]);
    }
    cout << ans * 2 << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
5 2 1
1 5
1 4
4 3
3 2
1 5
5 3
1 4
2 3
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 52220