#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5, logn = 20;
int n, x, y;
int p[maxn][logn];
int tin[maxn], tout[maxn], t;
int dep[maxn];
int can[maxn][2];
vector<int> gr[maxn], gb[maxn];

int read() {
  if (scanf("%d%d%d", &n, &x, &y) < 3) {
    return false;
  }
  x--;
  y--;
  for (int i = 0; i < n; i++) {
    gr[i].clear();
    gb[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    gr[v].push_back(u);
    gr[u].push_back(v);
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    gb[v].push_back(u);
    gb[u].push_back(v);
  }
  return true;
}

void buildLCA(int v) {
  tin[v] = t++;
  for (int i = 1; i < logn; i++) {
    p[v][i] = p[p[v][i - 1]][i - 1];
  }
  for (int i = 0; i < sz(gb[v]); i++) {
    int u = gb[v][i];
    if (u == p[v][0]) {
      continue;
    }
    p[u][0] = v;
    dep[u] = dep[v] + 1;
    buildLCA(u);
  }
  tout[v] = t++;
}

bool anc(int v, int u) {
  return tin[v] <= tin[u] && tout[v] >= tout[u];
}

int lca(int v, int u) {
  if (anc(v, u)) {
    return v;
  }
  if (anc(u, v)) {
    return u;
  }
  for (int i = logn - 1; i >= 0; i--) {
    if (!anc(p[v][i], u)) {
      v = p[v][i];
    }
  }
  return p[v][0];
}

int dist(int v, int u) {
  return dep[v] + dep[u] - 2 * dep[lca(v, u)];
}

int go(int v, int u) {
  if (anc(v, u)) {
    for (int i = logn - 1; i >= 0; i--) {
      if (!anc(p[u][i], v)) {
        u = p[u][i];
      }
    }
    return u;
  }
  return p[v][0];
}

void bfs() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      can[i][j] = false;
    }
  }
  vector< pair<int, int> > q;
  q.push_back(make_pair(x, y));
  can[x][0] = true;
  can[x][1] = true;
  for (int l = 0; l < sz(q); l++) {
    int v = q[l].first, u = q[l].second;
    for (int i = 0; i < sz(gr[v]); i++) {
      int vv = gr[v][i];
      if (can[vv][0]) {
        continue;
      }
      can[vv][0] = true;
      int uu = go(u, vv);
      if (uu != vv) {
        can[vv][1] = true;
        q.push_back(make_pair(vv, uu));
      }
    }
  }
}

void solve() {
  p[y][0] = y;
  dep[y] = 0;
  t = 0;
  buildLCA(y);
  bfs();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (can[i][0]) {
      ans = max(ans, 2 * dep[i]);
    }
    if (can[i][1]) {
      bool ok = false;
      for (int ii = 0; ii < sz(gr[i]); ii++) {
        int j = gr[i][ii];
        if (dist(i, j) > 2) {
          ok = true;
          break;
        }
      }
      if (ok) {
        ans = inf;
      }
    }
  }
  if (ans == inf) {
    ans = -1;
  }
  printf("%d\n", ans);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 57332