#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
vector <int> y[N];
ll h1[N],h2[N];
ll par[N];
void dfsg(ll v,ll p,ll h){
    h1[v]=h;
    for (auto u : g[v]){
        if (u==p) continue;
        dfsg(u,v,h+1);
    }
}
void dfsy(ll v,ll p,ll h){
    h2[v]=h;
    par[v]=p;
    for (auto u : y[v]){
        if (u==p) continue;
        dfsy(u,v,h+1);
    }
}
ll check(ll u,ll v){
    if (par[u]==par[v] || u==par[v] || v==par[u] || v==par[par[u]] || u==par[par[v]]) return 0;
    return 1;
}
ll dp[N];
void dfs(ll v,ll p){
    if (h1[v]>=h2[v]) return ;
    dp[v]=h2[v]-h1[v];
    dp[v]*=2;
    for (auto u : g[v]){
        if (p==u) continue;
        dfs(u,v);
        dp[v]=max(dp[v],dp[u]+2);
        if (check(u,v)) dp[v]=1e9;
    }
}
int32_t main(){
    ll n,x,y1;
    cin >> n >> x >> y1;
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        y[u].pb(v);
        y[v].pb(u);
    }
    dfsg(x,x,1);
    dfsy(y1,y1,1);
    dfs(x,x);
    if (dp[x]>=1e9) kill(-1);
    kill(dp[x]);

}
