#include <iostream>
#include <cstdio>
#include <vector> 
#define MN 201000

std::vector<int> v1[MN], v2[MN];
int dep[MN], fa[MN];
int Max = 0;

void dfs2(int x, int f)
{
	fa[x] = f; 
	for(auto y : v2[x]) 
	{
		if(y == f) continue;
		dep[y] = dep[x] + 1;
		dfs2(y, x);
	}
}

void dfs1(int x, int f, int t)
{
	if(dep[x] <= t) return;
	Max = std::max(Max, dep[x]);
	for(auto y : v1[x])
	{
		if(y == f) continue;
		if(fa[x] == fa[y] || fa[x] == y || fa[y] == x || fa[fa[x]] == y || fa[fa[y]] == x)
			dfs1(y, x, t + 1);
		else Max = 1e9;
	}
}

int main()
{
	int n, x, y; scanf("%d%d%d", &n, &x, &y);
	for(int i = 1; i < n; i++)
	{
		int u, v; scanf("%d%d", &u, &v);
		v1[u].push_back(v);
		v1[v].push_back(u);
	}
	for(int i = 1; i < n; i++)
	{
		int u, v; scanf("%d%d", &u, &v);
		v2[u].push_back(v);
		v2[v].push_back(u);
	}
	dfs2(y, 0); dfs1(x, 0, 0);
	if(Max >= 1e9) puts("-1");
	else printf("%d\n", 2 * Max);
} 