#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e5 + 100, maxlg = 20;
const ll inf = 2e18, mod = 1e9 + 7;

int n, X, Y, par[2][maxn][maxlg], h[2][maxn], st[2][maxn], et[2][maxn], curt;
vector<int> graph[2][maxn];
pair<int, int> edge[2][maxn], mn[2][maxn][maxlg];
bool mode = true;

void getH(int u, int prev, int tree)
{
	st[tree][u] = curt++;
	for (int i : graph[tree][u])
		if (i != prev)
		{
			h[tree][i] = h[tree][u] + 1;
			getH(i, u, tree);
		}
	et[tree][u] = curt;
}

bool isPar(int u, int v, int tree)
{
	return (st[tree][u] <= st[tree][v] && et[tree][v] <= et[tree][u]);
}

void prepLCA(int u, int prev, int tree)
{
	//if (tree == 0 && u == 0)
	//	cerr << '#' << mn[0][0][0].ff << ' ' << mn[0][0][0].ss << endl;
	for (int i : graph[tree][u])
		if (i != prev)
		{
			//if (tree == 0 && i == 0)
			//	cerr << "PREP " << i << ' ' << h[1][i] << endl;
			mn[tree][i][0] = mp(h[1][i], i);
			par[tree][i][0] = u;
			for (int j = 1; j < maxlg; j++)
			{
				par[tree][i][j] = par[tree][par[tree][i][j - 1]][j - 1];
				mn[tree][i][j] = min(mn[tree][i][j - 1], mn[tree][par[tree][i][j - 1]][j - 1]);
			}
			prepLCA(i, u, tree);
		}
}

int parent(int u, int h, int tree)
{
	for (int i = 0; i < maxlg; i++)
		if ((h >> i) & 1)
			u = par[tree][u][i];
	return u;
}

pair<int, int> getMin(int u, int h, int tree)
{
	pair<int, int> res = mp(mod, mod);
	for (int i =  0; i < maxlg; i++)
		if ((h >> i) & 1)
		{
			res = min(res, mn[tree][u][i]);
			u = par[tree][u][i];
		}
	return res;
}

int lca(int u, int v, int tree)
{
	if (h[tree][u] < h[tree][v])
		swap(u, v);
	u = parent(u, h[tree][u] - h[tree][v], tree);
	if (u == v)
		return u;
	for (int i = maxlg - 1; i >= 0; i--)
		if (par[tree][u][i] != par[tree][v][i])
		{
			u = par[tree][u][i];
			v = par[tree][v][i];
		}
	return par[tree][u][0];
}

int dist(int u, int v, int tree)
{
	int LCA = lca(u, v, tree);
	return (h[tree][u] + h[tree][v] - 2 * h[tree][LCA]);
}

pair<int, int> minPath(int u, int v, int tree)
{
	int LCA = lca(u, v, tree);
	return min(mn[tree][LCA][0], min(getMin(u, h[tree][u] - h[tree][LCA], tree), getMin(v, h[tree][v] - h[tree][LCA], tree)));
}

int HANDLE(int u)
{
	//if (mode)
	//	cerr << "MODE " << u << endl;
	int vert = minPath(X, u, 0).ss;
	int distY = dist(Y, vert, 1), distX = dist(X, vert, 0);
	//cerr << "HERE " << u << ' ' << vert << ':' << distY << ' ' << distX << endl;
	if (distY > distX)
	{
		if (mode)
			return -1;
		return max(dist(X, u, 0), dist(Y, u, 1)) * 2;
	}
	return distY + distX;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> X >> Y;
	X--;
	Y--;
	for (int tree = 0; tree < 2; tree++)
	{
		for (int i = 0; i < maxlg; i++)
			par[tree][Y][i] = Y, mn[tree][Y][i] = mp(0, Y);
		int u, v;
		for (int i = 0; i < n - 1; i++)
		{
			cin >> u >> v;
			edge[tree][i] = mp(--u, --v);
			graph[tree][u].pb(v);
			graph[tree][v].pb(u);
		}
	}

	for (int tree = 0; tree < 2; tree++)
	{
		curt = 0;
		getH(Y, -1, tree);
	}
	for (int tree = 0; tree < 2; tree++)
		prepLCA(Y, -1, tree);

	/*for (int i = 0; i < n; i++)
		cerr << '_' << h[1][i];
	cerr << endl;
	for (int i = 0; i < n; i++)
		cerr << '_' << mn[0][i][0].ff << ' ' << mn[0][i][0].ss;
	cerr << endl;*/

	int VERT = parent(X, h[1][X] - h[1][Y] - 1, 1);

	//cerr << "delta h " << h[1][X] - h[1][Y] << endl;
	//cerr << "VERT " << VERT << endl;

	bool win = false;
	for (int i = 0; i < n - 1; i++)
	{
		int u = edge[0][i].ff, v = edge[0][i].ss;
		if (dist(u, v, 1) > 2)
		{
			if (dist(u, X, 0) > dist(v, X, 0))
				swap(u, v);
			//cerr << "LONG EDGE " << u << ' ' << v << endl;
			if (isPar(VERT, u, 1) && HANDLE(u) == -1)
				win = true;
		}
	}
	mode = false;
	//cerr << '#' << win << endl;
	if (win)
		cout << -1 << endl;
	else
	{
		int ans = 0;
		for (int i = 0; i < n; i++)
			if (isPar(VERT, i, 1))
			{
				//cerr << "HANDLE " << i << ' ' << HANDLE(i) << endl;
				ans = max(ans, HANDLE(i));
			}
		cout << ans << endl;
	}
}



Measured memory_bytes: 140668