# include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn(2e5 + 5);

int n, x, y, lim[maxn], fa[maxn], ans, dis[maxn];
queue <int> q;
vector <int> edge1[maxn], edge2[maxn];

# define Orzyyb puts("-1"), exit(0)

inline void Add1(int u, int v) {
	edge1[u].push_back(v), edge1[v].push_back(u);
}

inline void Add2(int u, int v) {
	edge2[u].push_back(v), edge2[v].push_back(u);
}

inline int Dis(int x, int y) {
	if (fa[x] == y || fa[y] == x) return 1;
	if (fa[x] == fa[y] || fa[fa[x]] == y || fa[fa[y]] == x) return 2;
	return 233;
}

int main() {
	int i, u, v;
	scanf("%d%d%d", &n, &x, &y);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), Add1(u, v);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), Add2(u, v);
	lim[y] = 1, q.push(y);
	while (!q.empty()) {
		u = q.front(), q.pop();
		for (auto to : edge2[u])
			if (!lim[to]) fa[to] = u, lim[to] = lim[u] + 1, q.push(to);
	}
	for (i = 1; i <= n; ++i) --lim[i];
	dis[x] = 1, q.push(x);
	while (!q.empty()) {
		u = q.front(), q.pop();
		if (dis[u] - 1 > lim[u]) continue;
		ans = max(ans, lim[u]);
		if (dis[u] - 1 == lim[u]) continue;
		for (auto to : edge1[u]) if (Dis(u, to) > 2) Orzyyb;
		for (auto to : edge1[u])
			if (!dis[to]) dis[to] = dis[u] + 1, q.push(to);
	}
	printf("%d\n", ans << 1);
    return 0;
}