#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

template <class Type>
class LCA {
    public:
    LCA(int n);
    ~LCA();
    void add_edge(int from, int to, Type cost = 1);
    void add_undirected_edge(int from, int to, Type cost = 1);
    void init(int root = 0);
    int up(int x, int c);
    int lca(int x, int y);
    Type dist(int x, int y);
    
    private:
    struct edge {
        int to;
        Type cost;
        edge(int to, Type cost) : to(to), cost(cost) {}
    };
    vector <vector <edge> > graph;
    int size;
    int high;
    int *parent;
    int *depth;
    Type *distance;
    int dfs(int now, int par, int dep, Type dist);
};

template <class Type> LCA<Type>::LCA(int n) : size(n), high(32 - __builtin_clz(n)), graph(n) {
    parent = (int *)malloc(sizeof(int) * size * high);
    depth = (int *)malloc(sizeof(int) * size);
    distance = (Type *)malloc(sizeof(Type) * size);
}

template <class Type> LCA<Type>::~LCA() {
    free(parent);
    free(depth);
    free(distance);
}

template <class Type> void LCA<Type>::add_edge(int from, int to, Type cost) {
    graph[from].push_back(edge(to, cost));
}

template <class Type> void LCA<Type>::add_undirected_edge(int from, int to, Type cost) {
    graph[from].push_back(edge(to, cost));
    graph[to].push_back(edge(from, cost));
}

template <class Type> void LCA<Type>::init(int root) {
    dfs(root, -1, 0, 0);
    for (int i = 0; i + 1 < high; i++) {
        for (int j = 0; j < size; j++) {
            if (parent[j * high + i] == -1) {
                parent[j * high + i + 1] = -1;
            } else {
                parent[j * high + i + 1] = parent[parent[j * high + i] * high + i];
            }
        }
    }
}

template <class Type> int LCA<Type>::up(int x, int c) {
    while (c > 0) {
        int right = __builtin_ctz(c);
        x = parent[x * high + right];
        c ^= 1 << right;
    }
    return x;
}

template <class Type> int LCA<Type>::lca(int x, int y) {
    if (depth[x] > depth[y]) swap(x, y);
    y = up(y, depth[y] - depth[x]);
    if (x == y) return x;
    for (int i = 31 - __builtin_clz(depth[x]); i >= 0; i--) {
        if (parent[x * high + i] != parent[y * high + i]) {
            x = parent[x * high + i];
            y = parent[y * high + i];
        }
    }
    return parent[x * high];
}

template <class Type> Type LCA<Type>::dist(int x, int y) {
    return distance[x] + distance[y] - distance[lca(x, y)] * 2;
}

template <class Type> int LCA<Type>::dfs(int now, int par, int dep, Type dist) {
    int val = 1e9;
    for (int i = 0; i < graph[now].size(); i++) {
        if (graph[now][i].to != par) val = min(val, dfs(graph[now][i].to, now, dep + 1, dist + graph[now][i].cost) + 1);
    }
    parent[now * high] = par;
    depth[now] = dep;
    distance[now] = dist;
    return val;
}

int d[200000];
vector <int> v[200000];

int main() {
    int n, x, y, ans = 0, i;
    queue <int> q;
    
    scanf("%d %d %d", &n, &x, &y);
    
    x--;
    y--;
    
    LCA <int> l(n);
    
    for (i = 0; i < n - 1; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        a--;
        b--;
        
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    for (i = 0; i < n - 1; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        l.add_undirected_edge(a - 1, b - 1);
    }
    
    l.init();
    
    for (i = 0; i < n; i++) d[i] = -1;
    
    d[x] = 0;
    q.push(x);
    
    while (!q.empty()) {
        int x = q.front();
        
        q.pop();
        
        for (i = 0; i < v[x].size(); i++) {
            int nx = v[x][i];
            
            if (l.dist(x, nx) >= 3) {
                puts("-1");
                
                return 0;
            }
            
            if (d[nx] == -1 && l.dist(y, nx) > d[x] + 1) {
                d[nx] = d[x] + 1;
                q.push(nx);
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        if (d[i] >= 0) ans = max(ans, l.dist(y, i) * 2);
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 56448