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

const int N=200005;

struct node{
	int x,y;
	node(){}
	node(int x,int y):x(x),y(y){}
}a[N];
int n,x,y,S,T,cnt,rt,ans,z;
int dep[N],vis[N],dis[N],fa[N],in[N],ot[N],tag[N];
vector<int> lv1[N],lv2[N];
queue<int> q;

void dfs2(int k,int pre){
	int j,u;
	in[k]=++cnt;
	for (j=0;j<lv2[k].size();j++){
		u=lv2[k][j];
		if (u==pre) continue;
		dep[u]=dep[k]+1; fa[u]=k;
		dfs2(u,k);
	}
	ot[k]=++cnt;
}

bool check(int x,int y){
	if (in[x]>in[y]) swap(x,y);
	if (in[x]<in[y]&&ot[x]>in[y]) return (dep[y]-dep[x]>2);
	if (fa[x]==fa[y]) return 0;
	return 1;
}

void bfs(){
	int j,k,u;
	q.push(S); vis[S]=1;
	while (!q.empty()){
		k=q.front(); q.pop();
		for (j=0;j<lv1[k].size();j++){
			u=lv1[k][j];
			if (!vis[u]&&dis[k]+1<dep[u]){
				dis[u]=dis[k]+1;
				vis[u]=1;
				q.push(u);
			}
		}
	}
}

int main(){
	int i;
	scanf("%d%d%d",&n,&S,&T);
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		a[i]=node(x,y);
	}
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		lv2[x].push_back(y);
		lv2[y].push_back(x);
	}
	dfs2(T,0);
	for (i=1;i<n;i++){
		if (check(a[i].x,a[i].y)) tag[a[i].x]=tag[a[i].y]=1;
		else{
			lv1[a[i].x].push_back(a[i].y);
			lv1[a[i].y].push_back(a[i].x);
		}
	}
	bfs();
	for (i=1;i<=n;i++)
		if (tag[i]&&vis[i]){
			printf("-1\n");
			return 0;
		}
	for (i=1;i<=n;i++)
		if (vis[i]) ans=max(ans,dep[i]*2);
	printf("%d\n",ans);
	return 0;
}