#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 2e5+5;

int N,X,Y;
vector<int> c1[MX_N], c2[MX_N];

queue<int> q;
int d1[MX_N], d2[MX_N], p2[MX_N];
bool inf[MX_N];

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> X >> Y;
    FOR(i,1,N-1){
        int a,b; cin>>a>>b;
        c1[a].push_back(b);
        c1[b].push_back(a);
    }
    FOR(i,1,N-1){
        int a,b; cin>>a>>b;
        c2[a].push_back(b);
        c2[b].push_back(a);
    }

    memset(d2,-1,sizeof d2);
    memset(p2,-1,sizeof p2);
    d2[Y]=0; p2[Y]=0; q.push(Y);
    while(!q.empty()){
        int u=q.front(); q.pop();
        for(int v:c2[u])if(d2[v]==-1)d2[v]=d2[u]+1,p2[v]=u,q.push(v);
    }

    FOR(i,1,N) for(int v:c1[i]){
        int a=i,b=v; if(d2[a]<d2[b]) swap(a,b);
        if(p2[a]==b||p2[p2[a]]==b||p2[a]==p2[b]) continue;
        inf[i]=inf[v]=1;
    }

    int ans=d2[X]*2;
    memset(d1,-1,sizeof d1);
    d1[X]=0; q.push(X);
    while(!q.empty()){
        int u=q.front(); q.pop();
        if(inf[u]){ans=-1; break;}
        for(int v:c1[u])if(d1[v]==-1){d1[v]=d1[u]+1;ans=max(ans,d2[v]*2);if(d1[v]<d2[v])q.push(v);}
    }
    cout<<ans;
}

