#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 200000;

int n, p, q;
int eu[MaxN], ev[MaxN];

struct halfEdge
{
	int v;
	halfEdge *next;
};
halfEdge adj_pool[MaxN * 2], *adj_tail = adj_pool;
halfEdge *adj[MaxN + 1];

inline void addEdge(const int &u, const int &v)
{
	adj_tail->v = v, adj_tail->next = adj[u];
	adj[u] = adj_tail++;
}

inline void adj_init()
{
	adj_tail = adj_pool;
	for (int u = 1; u <= n; ++u)
		adj[u] = NULL;
}

int dfs_clock = 0;
int dfn_l[MaxN + 1], dfn_r[MaxN + 1];

int dep[MaxN + 1];

int fa[MaxN + 1];

void dfs1(int u)
{
	dfn_l[u] = ++dfs_clock;

	for (halfEdge *e = adj[u]; e; e = e->next)
		if (e->v != fa[u])
		{
			fa[e->v] = u;
			dep[e->v] = dep[u] + 1;
			dfs1(e->v);
		}

	dfn_r[u] = dfs_clock;
}

inline bool valid(int u, int v)
{
	if (dfn_l[u] > dfn_l[v])
		swap(u, v);
	if (dfn_l[v] <= dfn_r[u])
		return dep[v] - dep[u] <= 2;
	return fa[u] == fa[v];
}

bool inv[MaxN + 1];

int dist[MaxN + 1];
bool vis[MaxN + 1];

void dfs2(int u)
{
	vis[u] = true;

	for (halfEdge *e = adj[u]; e; e = e->next)
		if (!vis[e->v])
		{
			dist[e->v] = dist[u] + 1;
			if (dist[e->v] < dep[e->v])
				dfs2(e->v);
		}
}

inline int query()
{
	int res = 0;
	for (int u = 1; u <= n; ++u)
		if (vis[u])
		{
			res = max(res, dep[u]);
			if (inv[u])
				return -1;
		}
	return res * 2;
}

int main()
{
	cin >> n >> p >> q;
	for (int i = 1; i < n; ++i)
		eu[i] = getint(), ev[i] = getint();
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint();
		addEdge(u, v);
		addEdge(v, u);
	}

	dfs1(q);

	adj_init();

	for (int i = 1; i < n; ++i)
	{
		int u = eu[i], v = ev[i];
		if (!valid(u, v))
			inv[u] = inv[v] = true;
		else
		{
			addEdge(u, v);
			addEdge(v, u);
		}
	}

	dfs2(p);

	cout << query() << endl;

	return 0;
}