#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int MaxN = 2e5 + 5;

vector<int> gb[MaxN], gr[MaxN];

int dep[MaxN], fa[MaxN], d[MaxN];
bool safe[MaxN], vis[MaxN];

void Dfs(int x, int f) {
  ::fa[x] = f;
  for (int k : gb[x]) {
    if (k != f) {
      dep[k] = dep[x] + 1;
      Dfs(k, x);
    }
  }
}

#define fin cin
#define fout cout

int main() {
  ios_base::sync_with_stdio(false);
  int n, sx, sy;
  fin >> n >> sx >> sy;
  for (int i = 1; i < n; ++i) {
    int x, y;
    fin >> x >> y;
    gr[x].emplace_back(y);
    gr[y].emplace_back(x);
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    fin >> x >> y;
    gb[x].emplace_back(y);
    gb[y].emplace_back(x);
  }
  Dfs(sy, -1);
  for (int i = 1; i <= n; ++i) {
    for (int k : gr[i]) {
      if (![](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
      } (i, k)) {
        safe[i] = safe[k] = true;
      }
    }
  }
  if (safe[sx]) {
    fout << -1 << endl;
    return 0;
  }
  int ans = 0;
  memset(d, 0xff, sizeof d);
  d[sx] = 0;
  queue<int> Q;
  Q.push(sx);
  while (!Q.empty()) {
    int k = Q.front();
    Q.pop();
    if (d[k] >= dep[k]) {
      continue;
    }
    if (safe[k]) {
      fout << -1 << endl;
      return 0;
    }
    ans = max(ans, dep[k] * 2);
    for (int x : gr[k]) {
      if (!vis[x] && d[k] + 1 < dep[x] && [](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
        } (k, x)) {
        d[x] = d[k] + 1;
        vis[x] = true;
        Q.push(x);
      }
    }
  }
  fout << ans << endl;
  return 0;
}
