#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int n;
vvi s, t;
vi ds, dt;

// LCA (0-indexed)
struct LCA {
  int n, bi;
  vi dep;
  vector<vi> to, par;
  LCA(int n):n(n),dep(n),to(n){}
  void add(int a, int b){ to[a].pb(b); to[b].pb(a);}
  void calcDep(int v, int ndep=0, int p=-1){
    dep[v] = ndep; par[0][v] = p;
    for(int u : to[v]) if(u != p) calcDep(u,ndep+1,v);
  }
  void init(){
    bi = 0;
    while(1<<bi <= n) bi++;
    par.resize(bi,vi(n,-1));
    calcDep(0);
    rep(i,bi-1)rep(j,n) par[i+1][j] = (par[i][j]==-1?-1:par[i][par[i][j]]);
  }
  int lca(int a, int b){
    if(dep[a] < dep[b]) swap(a,b);
    int x = dep[a]-dep[b];
    for(int i = bi-1; i >= 0; --i){
      if(1<<i <= x) a = par[i][a], x -= 1<<i;
    }
    if(a == b) return a;
    for(int i = bi-1; i >= 0; --i){
      if(par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];
    }
    return par[0][a];
  }
  int dist(int a, int b){
    int c = lca(a,b);
    return dep[a]+dep[b] - dep[c]*2;
  }
};
//

void bfs(vvi& g, vi& d, int sv) {
  d[sv] = 0;
  queue<int> q;
  q.push(sv);
  while (sz(q)) {
    int v = q.front(); q.pop();
    for (int u : g[v]) {
      if (d[u] == INF) {
        d[u] = d[v]+1;
        q.push(u);
      }
    }
  }
}
void cfs(vvi& g, vi& d, int sv) {
  if (d[sv] != 1) return;
  d[sv] = 2;
  queue<int> q;
  q.push(sv);
  while (sz(q)) {
    int v = q.front(); q.pop();
    for (int u : g[v]) {
      if (d[u] == 1) {
        d[u] = 2;
        q.push(u);
      }
    }
  }
}

int main() {
  scanf("%d",&n);
  int x, y;
  scanf("%d%d",&x,&y);
  --x; --y;
  s = t = vvi(n);
  LCA g(n);
  rep(i,n-1) {
    int a, b;
    scanf("%d%d",&a,&b);
    --a; --b;
    s[a].pb(b);
    s[b].pb(a);
  }
  rep(i,n-1) {
    int a, b;
    scanf("%d%d",&a,&b);
    --a; --b;
    t[a].pb(b);
    t[b].pb(a);
    g.add(a,b);
  }
  g.init();
  ds = dt = vi(n,INF);
  bfs(s,ds,x);
  bfs(t,dt,y);
  int ans = 0;
  vi c(n);
  rep(i,n) if (ds[i] < dt[i]) c[i] = 1;
  cfs(s,c,x);
  rep(i,n) {
    if (c[i] != 2) continue;
    maxs(ans, dt[i]*2);
    for (int u : s[i]) {
      // if (c[u] != 2) continue;
      if (g.dist(i,u) >= 3) {
        puts("-1");
        return 0;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 55796