#include<bits/stdc++.h>

using namespace std;

int ans, N, X, Y, niv[200009], t[200009], dp[200009];
bool safe[200009];
vector < int > red[200009], blue[200009];
queue < int > cc;

void dfsBlue (int nod, int tata)
{
    t[nod] = tata;
    for (auto it = blue[nod].begin (); it != blue[nod].end (); it ++)
        if (*it != tata)
            niv[*it] = niv[nod] + 1, dfsBlue (*it, nod);
}

bool atMost2BlueD (int x, int y) {return (t[x] == t[y] || x == t[y] || y == t[x] || x == t[t[y]] || y == t[t[x]]);}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d\n", &N, &X, &Y);
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    red[x].push_back (y);
    red[y].push_back (x);
}
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    blue[x].push_back (y);
    blue[y].push_back (x);
}
dfsBlue (Y, -1);
for (int i=1; i<=N; i++)
    for (auto it = red[i].begin (); it != red[i].end (); it ++)
        if (!atMost2BlueD (i, *it))
            safe[i] = safe[*it] = 1;
if (safe[X])
{
    printf ("-1\n");
    return 0;
}
for (int i=1; i<=N; i++)
    dp[i] = N + 2;
dp[X] = 0, cc.push (X), ans = niv[X];
while (!cc.empty ())
{
    int nod = cc.front ();
    cc.pop ();
    if (dp[nod] >= niv[nod]) continue;
    if (niv[nod] > ans) ans = niv[nod];
    if (safe[nod])
    {
        printf ("-1\n");///Escape
        return 0;
    }
    for (auto it = red[nod].begin (); it != red[nod].end (); it ++)
        if (dp[*it] > dp[nod] + 1 && atMost2BlueD (nod, *it))
            dp[*it] = dp[nod] + 1, cc.push (*it);
}
printf ("%d\n", 2 * ans);
return 0;
}
