#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], B[MAXN];
int h[MAXN], par[MAXN];
int dp[MAXN];
bool good[MAXN];
queue<int> Q;
vector<int> G[MAXN], adj[MAXN];

void dfs(int node){
	h[node]=h[par[node]]+1;
	for (int v:G[node]) if (v!=par[node]){
		par[v]=node;
		dfs(v);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>x>>y;
	for (int i=1; i<n; i++) cin>>A[i]>>B[i];
	for (int i=1; i<n; i++){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	h[0]=-1;
	dfs(y);
	for (int i=1; i<n; i++){
		int u=A[i], v=B[i], d=0;
		while (u!=v && d<=2){
			if (h[u]>h[v]) swap(u, v);
			v=par[v];
			d++;
		}
		if (d==3) good[A[i]]=good[B[i]]=1;
		else{
			adj[A[i]].pb(B[i]);
			adj[B[i]].pb(A[i]);
		}
	}
	memset(dp, 63, sizeof(dp));
	dp[x]=0;
	Q.push(x);
	while (Q.size()){
		int v=Q.front();
		Q.pop();
		if (h[v]<dp[v]) continue ;
//		debug2(v, dp[v])
		ans=max(ans, 2*h[v]);
		if (h[v]==dp[v]) continue ;
		if (good[v]) kill(-1)
		for (int u:adj[v]) if (dp[u]>dp[v]+1){
			dp[u]=dp[v]+1;
			Q.push(u);
		}
	}
	cout<<ans<<"\n";
	
	return 0;
}
