#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define maxn 200005
using namespace std;
int n,x,y,dep[maxn],fa[maxn],l[maxn],r[maxn],cnt,u1[maxn],v1[maxn],dist[maxn],ans;
bool vis[maxn],islong[maxn];
struct node { int v; node *nxt; } edge[maxn*4],*head[2][maxn],*ncnt;
queue<int> q;
void addedge(int x,int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[x][u];
	head[x][u]=ncnt;
}
void dfs(int u)
{
	l[u]=++cnt;
	for(node *p=head[1][u];p;p=p->nxt)
	{
		int v=p->v;
		if(v==fa[u]) continue;
		fa[v]=u,dep[v]=dep[u]+1;
		dfs(v);
	}
	r[u]=++cnt;
}
bool check(int x,int y)
{
	if(l[x]>l[y]) swap(x,y);
	if(l[x]<=l[y]&&r[y]<=r[x]) return dep[y]-dep[x]>2;
	else return fa[x]!=fa[y];
}
void bfs()
{
	while(!q.empty()) q.pop();
	vis[x]=true; q.push(x);
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(node *p=head[0][u];p;p=p->nxt)
		{
			int v=p->v;
			if(vis[v]) continue;
			dist[v]=dist[u]+1;
			if(dist[v]<dep[v]) { vis[v]=true; q.push(v); }
		}
	}
}
void read(int &x)
{
	char ch=getchar(); x=0;
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
}
int main()
{
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		ans=0;
		memset(vis,0,sizeof(vis));
		memset(islong,0,sizeof(islong));
		memset(head,0,sizeof(head));
		ncnt=&edge[0];
		for(int i=1;i<n;i++) { read(u1[i]); read(v1[i]); }//scanf("%d%d",&u1[i],&v1[i]);
		for(int i=1;i<n;i++)
		{
			int u,v;
			read(u); read(v);//scanf("%d%d",&u,&v);
			addedge(1,u,v); addedge(1,v,u);
		}
		fa[y]=dep[y]=0; dfs(y);
		for(int i=1;i<n;i++)
			if(check(u1[i],v1[i])) islong[u1[i]]=islong[v1[i]]=true;
			else { addedge(0,u1[i],v1[i]); addedge(0,v1[i],u1[i]); }
		dist[x]=0; bfs();
		int ans=0;
		for(int i=1;i<=n&&ans!=-1;i++)
			if(vis[i]&&islong[i]) ans=-1;
			else if(vis[i]) ans=max(ans,dep[i]*2);
		printf("%d\n",ans);
	}
}