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

const int N = 2e5 + 100, inF = N;

int n, DIS[N];
bool mark[N];
struct tree {
	int dex, root, dis[N], par[N];
	vector<int> nei[N];
	tree() {
		fill(par, par + N, -1);
		fill(dis, dis + N, inF);
	}
	void input() {
		for (int i = 0; i < n - 1; i++) {
			int u, v;
			cin >> u >> v;
			nei[--u].push_back(--v);
			nei[v].push_back(u);
		}
	}
	void dfs(int v, bool b = false) {
		dis[root] = 0;
		if (dis[v] >= DIS[v] && b)
			return;
		for (int u: nei[v])
			if (u ^ par[v]) {
				dis[u] = dis[v] + 1;
				par[u] = v;
				dfs(u, b);
			}
	}
	bool far(int u, int v) {
		if (u == v || u == par[v] || v == par[u] || par[u] == par[v])
			return false;
		if (par[u] != -1 && par[par[u]] == v)
			return false;
		if (par[v] != -1 && par[par[v]] == u)
			return false;
		return true;
	}
} R, B;

void INPUT() {
	cin >> n >> R.root >> B.root;
	R.root--;
	B.root--;
	R.input();
	B.input();
	B.dfs(B.root);
	copy(B.dis, B.dis + n, DIS);
	R.dfs(R.root, true);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	INPUT();
	for (int v = 0; v < n; v++)
		for (int u: R.nei[v])
			if (B.far(u, v))
				mark[u] = mark[v] = true;
	for (int v = 0; v < n; v++)
		if (R.dis[v] < B.dis[v] && mark[v]) {
			cout << -1;
			return 0;
		}
	int a = -1, b = inF;
	for (int v = 0; v < n; v++) {
		if (R.dis[v] < B.dis[v])
			a = max(a, B.dis[v]);
		if (R.dis[v] <= B.dis[v])
			b = min(b, B.dis[v]);
	}
	cout << max(a, b) * 2;
}
