#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int n;
vector<vector<int> > g,h;
vector<int>  dep;
vector<vector<int> > p;
vector<bool> ng;
void dfsinit(int id,int pre){
    if(id==0){
        dep[id] = 0;
        p[id][0] = 0;
    }else{
        dep[id] = dep[pre]+1;
        p[id][0] = pre;
    }
    for(auto x:h[id]){
        if(x!=pre){
            dfsinit(x,id);
        }
    }
}
void init(){
    dep.resize(n);
    p.resize(n);
    rep(i,n){
        p[i].resize(20);
    }
    dfsinit(0,-1);
    for(int k=1;k<20;k++){
        rep(i,n){
            p[i][k] = p[p[i][k-1]][k-1];
        }
    }
}
int lca(int a,int b){
    if(dep[a]>dep[b])swap(a,b);
    for(int k=0;k<20;k++){
        if((dep[b]-dep[a])>>k & 1){
            b = p[b][k];
        }
    }
    if(a==b)return a;
    for(int k=19;k>=0;k--){
        if(p[a][k]!=p[b][k]){
            a = p[a][k];
            b = p[b][k];
        }
    }
    return p[a][0];
}
int dist(int a,int b){
    int c = lca(a,b);
    return dep[a] + dep[b] - 2*dep[c];
}
int next(int x,int y){
    int z = lca(x,y);
    if(x==z){
        return p[y][0];
    }else if(y==z){
        int s = dep[x]-dep[y]-1;
        for(int k=0;k<20;k++){
            if((s)>>k & 1){
                x = p[x][k];
                s -= (1<<k);
            }
        }
        return x;
    }else{
        return p[y][0];
    }
}
bool flag = 0;
void dfs(int x,int y,int pre){
    if(ng[x]){
        flag = true;
        return;
    }
    for(auto z:g[x]){
        if(z==pre)continue;
        if(dist(y,z)<=1)continue;
        dfs(z,next(z,y),x);
    }
    return ;
}
int dfs2(int x,int y,int pre){
    int mx = 2*(dist(x,y));
    for(auto z:g[x]){
        if(z==pre)continue;
        if(dist(y,z)<=1)continue;
        mx = max(mx,2+dfs2(z,next(z,y),x));
    }
    return mx;
}
int main(){
    cin >> n;
    g.resize(n);
    h.resize(n);
    ng.resize(n);
    int x,y;
    cin >> x >> y;
    x--;y--;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        h[a].push_back(b);
        h[b].push_back(a);
    }
    init();
    rep(i,n){
        for(auto z:g[i]){
            if(dist(i,z)>=3){
                ng[i] = true;
                ng[z] = true;
            }
        }
    }
    dfs(x,y,-1);
    if(flag){
        cout << -1 << endl;
        return 0;
    }
    cout << dfs2(x,y,-1) << endl;
    return 0;
}

Measured memory_bytes: 61696