// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<queue>

using namespace std;

const int N=2e5+10;

struct Tree

{

	struct edge{int next,to;}a[N<<1];

	int head[N],cnt;

	void link(int x,int y)

		{

			a[++cnt]=(edge){head[x],y};head[x]=cnt;

			a[++cnt]=(edge){head[y],x};head[y]=cnt;

		}

}A,B;

int n,p1,p2,dep[N],dis[N],fr[N],vis[N],ans;

queue<int> Q;

void bfs1()

{

	memset(dis,-1,sizeof(dis));

	if(dep[p1]) Q.push(p1);dis[p1]=0;

	while(!Q.empty())

	{

		int x=Q.front();Q.pop();vis[x]=1;

		for(int i=A.head[x];i;i=A.a[i].next)

		{

			int R=A.a[i].to;

			if(dis[R]==-1)

			{

				dis[R]=dis[x]+1;

				if(dis[R]<dep[R]) Q.push(R);

				else if(dis[R]==dis[R]) vis[R]=1;

			}

		}

	}

}

void bfs2()

{

	memset(dep,-1,sizeof(dep));

	Q.push(p2);dep[p2]=0;

	while(!Q.empty())

	{

		int x=Q.front();Q.pop();

		for(int i=B.head[x];i;i=B.a[i].next)

		{

			int R=B.a[i].to;

			if(dep[R]==-1) dep[R]=dep[x]+1,fr[R]=x,Q.push(R);

		}

	}

}

int Dis(int x,int y)

{

	if(dep[x]<dep[y]) swap(x,y);

	if(fr[x]==fr[y]||x==y||fr[x]==y) return 0;

	if(fr[fr[x]]==y) return 0;

	return 1;

}

int main()

{

	cin>>n>>p1>>p2;

	for(int i=1,x,y;i<n;i++) scanf("%d%d",&x,&y),A.link(x,y);

	for(int i=1,x,y;i<n;i++) scanf("%d%d",&x,&y),B.link(x,y);

	bfs2();bfs1();

	for(int x=1;x<=n;x++)

		for(int i=A.head[x];i;i=A.a[i].next)

			if(vis[x]&&vis[A.a[i].to]&&Dis(x,A.a[i].to))

				puts("-1"),exit(0);

	for(int i=1;i<=n;i++) if(vis[i]) ans=max(dep[i],ans);

	cout<<ans*2<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 2.6586250466864243x):
#include<bits/stdc++.h>

#define MAXN 200005

using namespace std;

//小号提交大号的代码别棕啊qwq

int n,cnt,last[MAXN];

int father[MAXN],deep[MAXN],dis[MAXN];

int q[MAXN],nnn[MAXN],mx[MAXN];

int tim,a[MAXN][2],xx,yy;

bool vis[MAXN],win[MAXN];



struct edge

{

    int to,next,h;

}t[MAXN*4];



void add(int u,int v,int h)

{

    t[++cnt].to=v;t[cnt].h=h;

    t[cnt].next=last[u];last[u]=cnt;

    t[++cnt].to=u;t[cnt].h=h;

    t[cnt].next=last[v];last[v]=cnt;

}



void dfs(int x)

{

    deep[x]=deep[father[x]]+1;nnn[x]=++tim;

    for (int i=last[x];i;i=t[i].next)

        if (t[i].to!=father[x]) father[t[i].to]=x,dfs(t[i].to);

    mx[x]=++tim;

}



bool check(int x,int y)

{

    if (nnn[x]>nnn[y]) swap(x,y);

    if (nnn[x]<nnn[y]&&mx[x]>nnn[y]) return deep[y]-deep[x]>2 ? true : false;

    if (father[x]==father[y]) return false;

    return true;

}



void bfs()

{

    int h=1,tt=1;q[1]=xx;vis[xx]=1;

    while (h<=tt)

    {

        int x=q[h++];

        for (int i=last[x];i;i=t[i].next)

            if (!t[i].h&&!vis[t[i].to])

            {

                dis[t[i].to]=dis[x]+1;

                if (dis[t[i].to]<deep[t[i].to]) vis[t[i].to]=1,q[++tt]=t[i].to;

            }

    }

}



int max(int a,int b){return a>b?a:b;}



template<class T>inline void read(T &res)

{

    static char ch;T flag=1;

    while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;

    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;

}



int main()

{

    int ans=0;

    read(n);read(xx);read(yy);



    for (int i=1;i<n;i++) {read(a[i][0]);read(a[i][1]);}

    for (int i=1;i<n;i++)

    {

        int x,y;

        read(x);read(y);

        add(x,y,1);

    }



    deep[0]=-1;

    dfs( yy );



    for (int i=1;i<n;i++)

    {

        if (check(a[i][0],a[i][1]))

            win[a[i][0]]=win[a[i][1]]=1;

        else add(a[i][0],a[i][1],0);

    }



    bfs();



    for (int i=1;i<=n;i++)

        if (win[i]&&vis[i])

            {putchar('-');putchar('1');return 0;}



    for (int i=1;i<=n;i++)

        if (vis[i])

            ans=max(ans,deep[i]<<1);



    printf("%d\n",ans);

    return 0;

}