#include <cstdio>
#include <vector>

const int MN = 200005;

int N, X, Y, Ans;
std::vector<int> G[2][MN];

int par[MN], dep[MN];
void DFS0(int u, int p) {
	dep[u] = dep[par[u] = p] + 1;
	for (int v : G[1][u]) if (v != p) DFS0(v, u);
}

void DFS1(int u, int p, int d) {
	int win = 0;
	Ans = std::max(Ans, dep[u]);
	for (int v : G[0][u]) if (v != p) {
		if (u == par[v] || v == par[u] || u == par[par[v]] || v == par[par[u]] || par[u] == par[v]) {
			if (d + 1 < dep[v]) DFS1(v, u, d + 1);
		} else { win = 1; break; }
	}
	if (win) Ans = N;
}

int main() {
	scanf("%d%d%d", &N, &X, &Y);
	for (int o = 0; o < 2; ++o)
		for (int i = 1, x, y; i < N; ++i)
			scanf("%d%d", &x, &y),
			G[o][x].push_back(y),
			G[o][y].push_back(x);
	dep[0] = -1, DFS0(Y, 0);
	DFS1(X, 0, 0);
	printf("%d\n", Ans == N ? -1 : 2 * Ans);
	return 0;
}