#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, x, y, fa[maxn], dep[maxn];
struct Tree {
  int tote, FIR[maxn], TO[maxn], NEXT[maxn];
  void addedge(int u, int v) {
    TO[++tote] = v;
    NEXT[tote] = FIR[u];
    FIR[u] = tote;
  }
  void dfs(int u) {
    for (int p = FIR[u]; p; p = NEXT[p]) {
      int v = TO[p];
      if (fa[u] == v) continue;
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
    }
  }
  int solve(int u, int f, int dis) {
    int Ans = dep[u];
    for (int p = FIR[u]; p; p = NEXT[p]) {
      int v = TO[p];
      if (v == f) continue;
      if (dis + 1 >= dep[v]) continue;
      bool flag = fa[v] == u || fa[u] == v || fa[fa[v]] == u ||
                  fa[fa[u]] == v || fa[u] == fa[v];
      if (!flag) return 1e8;
      Ans = max(Ans, solve(v, u, dis + 1));
    }
    return Ans;
  }
} red, blue;
int main() {
  int i, u, v;
  scanf("%d%d%d", &n, &x, &y);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    red.addedge(u, v);
    red.addedge(v, u);
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    blue.addedge(u, v);
    blue.addedge(v, u);
  }
  blue.dfs(y);
  int Ans = red.solve(x, 0, 0);
  if (Ans >= 1e7)
    puts("-1");
  else
    printf("%d\n", Ans * 2);
}
