#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int N=200005;
const int LGN=18;
const int E=N<<1;

struct tree
{
	int tov[E],nxt[E];
	int last[N];
	int tot;

	inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}
}t[2];

int LOG[N],depth[N];
int anc[N][LGN];
int n,srcx,srcy,ans;

void dfs(int x)
{
	for (int i=t[1].last[x],y;i;i=t[1].nxt[i])
		if ((y=t[1].tov[i])!=anc[x][0]) depth[y]=depth[anc[y][0]=x]+1,dfs(y);
}

void pre()
{
	LOG[1]=0;
	for (int i=2;i<=n;++i) LOG[i]=LOG[i-1]+(1<<LOG[i-1]+1==i);
	for (int i=1;i<=LOG[n];++i)
		for (int x=1;x<=n;++x)
			anc[x][i]=anc[anc[x][i-1]][i-1];
}

inline int adjust(int x,int h)
{
	for (int i=LOG[depth[x]];i>=0;--i) if (depth[anc[x][i]]>=h) x=anc[x][i];
	return x;
}

inline int lca(int x,int y)
{
	if (depth[x]>depth[y]) swap(x,y);
	y=adjust(y,depth[x]);
	if (x==y) return x;
	for (int i=LOG[depth[x]];i>=0;--i) if (anc[x][i]!=anc[y][i]) x=anc[x][i],y=anc[y][i];
	return anc[x][0];
}

inline int dist(int x,int y){return depth[x]+depth[y]-(depth[lca(x,y)]<<1);}

void calc(int x,int fa=0,int cur=0)
{
	if (cur>=depth[x]-1) return;
	ans=max(ans,depth[x]-1<<1);
	for (int i=t[0].last[x],y;~ans&&i;i=t[0].nxt[i])
		if ((y=t[0].tov[i])!=fa)
		{
			if (dist(x,y)>2) ans=-1;
			else calc(y,x,cur+1);
		}
}

int main()
{
	//freopen("sugigma.in","r",stdin),freopen("sugigma.out","w",stdout);
	n=read(),srcx=read(),srcy=read();
	for (int s=0;s<2;++s)
		for (int i=1,x,y;i<n;++i)
			x=read(),y=read(),t[s].insert(x,y),t[s].insert(y,x);
	depth[srcy]=1,dfs(srcy),pre(),ans=0,calc(srcx);
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}