#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

struct HeavyLightDecomposition{
  int root;
  // tree representation
  int N;              // size
  vi parent;          // parent[p] := parent of node p
  vi depth;           // depth[p] := depth of node p
  vi subtreesize;     // subtreesize[p] := size of subtree rooted at node p

  // heavy light decomposition
  vector<vi> paths;   // paths[i] := heavy edge path (id=i)
  vi belongs;         // belongs[p] := id of path that node p belongs to
  vi pathpos;         // pathpos[p] := index of node p in paths[belongs[p]] (paths[belongs[p]][pathpos[p]] == p) (for segment tree)
  vi heavyedge;       // heavyedge[p] := edge (p,heavyedge[p]) is heavy edge

  // tree construct dfs
  int treedfs(int p,int d,int bef,vi g[]){
    parent[p] = bef;
    depth[p] = d;
    subtreesize[p] = 1;
    int maxchild = -1;
    REP(i,g[p].size()){
      int to = g[p][i];
      if(to==bef)continue;
      subtreesize[p] += treedfs(to,d+1,p,g);
      if(maxchild == -1 || subtreesize[maxchild] < subtreesize[to]){
        maxchild = to;
      }
    }
    if(maxchild != -1 && subtreesize[maxchild]*2 >= subtreesize[p]){
      heavyedge[p] = maxchild;
    }
    return subtreesize[p];
  }

  // heavy light decomposition dfs
  void decompositiondfs(int pathid,int head,int bef,vi g[]){
    paths.push_back(vi());
    int cur = head;
    while(true){
      belongs[cur] = pathid;
      pathpos[cur] = paths[pathid].size();
      paths[pathid].push_back(cur);
      int nxt = heavyedge[cur];
      REP(i,g[cur].size()){
        int to = g[cur][i];
        if(to==bef)continue;
        if(to==nxt)continue;
        decompositiondfs(paths.size(),to,cur,g);
      }
      if(nxt==-1)break;
      bef = cur;
      cur = nxt;
    }
  }

  HeavyLightDecomposition(int n,vi g[],int _root){
    N = n;
    root = _root;
    parent.assign(n,-1);
    depth.assign(n,-1);
    subtreesize.assign(n,-1);
    belongs.assign(n,-1);
    pathpos.assign(n,-1);
    heavyedge.assign(n,-1);
    
    treedfs(root,0,-1,g);
    decompositiondfs(0,root,-1,g);
  }

  int lca(int a,int b){
    int ato = paths[belongs[a]][0];
    int bto = paths[belongs[b]][0];
    while(belongs[a]!=belongs[b]){
      if(depth[ato] > depth[bto]){
        a = ato;
        if(a!=root){
          a = parent[a];
          ato = paths[belongs[a]][0];
        }
      }else{
        b = bto;
        if(b!=root){
          b = parent[b];
          bto = paths[belongs[b]][0];
        }
      }
    }
    if(depth[a]<=depth[b]){
      return a;
    }else{
      return b;
    }
  }

  int length(int a,int b){
    return depth[a]+depth[b]-2*depth[lca(a,b)];
  }
};

int n,x,y;
vi red[252521];
vi blue[252521];
bool win[252521];
int reddepth[252521];
// sigma is red in x
// sugim is blue in y
// sugim chases sigma
// sigma first

int main(){
  scanf("%d%d%d",&n,&x,&y);
  --x;--y;
  REP(i,n-1){
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    red[a].push_back(b);
    red[b].push_back(a);
  }
  REP(i,n-1){
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    blue[a].push_back(b);
    blue[b].push_back(a);
  }
  // search win point
  HeavyLightDecomposition hld(n,blue,y);
  REP(i,n){
    REP(j,red[i].size()){
      int to = red[i][j];
      // avoid duplication
      if(i<to){
        if(hld.length(i,to)>=3){
          win[i] = true;
          win[to] = true;
        }
      }
    }
  }
  // flee
  REP(i,n)reddepth[i] = 252521;
  reddepth[x] = 0;
  stack<int> S;
  S.push(x);
  while(!S.empty()){
    int p = S.top();S.pop();
    int d = reddepth[p]+1;
    REP(i,red[p].size()){
      int to = red[p][i];
      if(reddepth[to] < d)continue;
      if(hld.depth[to] <= d)continue;
      reddepth[to] = d;
      S.push(to);
    }
  }
  // check
  int ans = -1;
  REP(i,n){
    if(reddepth[i]!=252521){
      if(win[i]){
        ans = -2;
        break;
      }else{
        CHMAX(ans,hld.depth[i]);
      }
    }
  }
  if(ans==-2){
    puts("-1");
  }else{
    printf("%d\n",ans*2);
  }
  return 0;
}


Measured memory_bytes: 43184