/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

class LCA{
	public:
	int N,root,max_log;
	vvi G,parent;
	vi depth;
	LCA(int size){
		N=size;
		G=vvi(size);
		max_log=20;
		depth=vi(size);
		parent=vvi(max_log,vi(size));
	}
	void add_edge(int a,int b){
		G[a].pb(b);
		G[b].pb(a);
	}
	void dfs(int v,int p,int d){
		parent[0][v]=p;
		depth[v]=d;
		rep(i,G[v].size())if(G[v][i]!=p)dfs(G[v][i],v,d+1);
	}
	void init(){
		root=0;
		dfs(root,-1,0);
		for(int k=0;k+1<max_log;k++){//doubling
			for(int v=0;v<N;v++){
				if(parent[k][v]<0)parent[k+1][v]=-1;
				else parent[k+1][v]=parent[k][parent[k][v]];
			}
		}
	}
	int lca(int u,int v){
		int out=depth[u]+depth[v];
		if(depth[u]>depth[v])swap(u,v);
		rep(k,max_log)if((depth[v]-depth[u])>>k&1)v=parent[k][v];
		if(u==v){
			out-=2*depth[u];
			return out;
		}
		for(int k=max_log-1;k>=0;k--){
			if(parent[k][u]!=parent[k][v]){
				u=parent[k][u];
				v=parent[k][v];
			}
		}
		out-=2*depth[parent[0][u]];
		return out;
	}
};
int n,x,y,out;
vvi G,tG;
vi co,h;
void dfs1(int a,int p,int c){
	co[a]=c;
	rep(i,tG[a].size()){
		int to=tG[a][i];
		if(to==p)continue;
		dfs1(to,a,c+1);
	}
}
void dfs2(int a,int p,int c){
	if(c>=co[a])return;
	if(h[a])out=inf;
	cmax(out,2*co[a]);
	rep(i,G[a].size()){
		int to=G[a][i];
		if(to==p)continue;
		dfs2(to,a,c+1);
	}
}
signed main(){
	cin>>n>>x>>y;
	G=tG=vvi(n);
	co=h=vi(n);
	LCA lca(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		lca.add_edge(a,b);
		tG[a].pb(b);
		tG[b].pb(a);
	}
	lca.init();
	rep(i,n)rep(j,G[i].size()){
		int to=G[i][j];
		if(lca.lca(i,to)>=3)h[i]=h[to]=1;
	}
	dfs1(y-1,-1,0);
	dfs2(x-1,-1,0);
	if(out==inf)cout<<-1<<endl;
	else cout<<out<<endl;
}















Measured memory_bytes: 77936