#include <bits/stdc++.h>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ') {
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
const int N = 2e5 + 5;
struct Edge {
  int next, to;
  Edge(int next = 0, int to = 0) : next(next), to(to){};
} edge[N << 2];
int ha[N], hb[N], tot;
void _add(int *h, int x, int y) {
  edge[++tot] = Edge(h[x], y);
  h[x] = tot;
}
void add(int *h, int x, int y) {
  _add(h, x, y);
  _add(h, y, x);
}
int fa[N], son[N], size[N], top[N], d[N];
int ans, cir;
void dfs(int x) {
  size[x] = 1;
  for (int i = hb[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (y == fa[x]) continue;
    d[y] = d[x] + 1, fa[y] = x, dfs(y), size[x] += size[y],
    son[x] = size[son[x]] > size[y] ? son[x] : y;
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return d[x] < d[y] ? x : y;
}
int dis(int x, int y) { return d[x] + d[y] - 2 * d[lca(x, y)]; }
void dfs(int x, int topf) {
  top[x] = topf;
  if (son[x]) dfs(son[x], topf);
  for (int i = hb[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (y != fa[x] && y != son[x]) dfs(y, y);
  }
}
void escape(int x, int fa, int dep) {
  ans = max(ans, d[x] << 1);
  for (int i = ha[x]; i; i = edge[i].next) {
    int y = edge[i].to;
    if (dis(x, y) > 2) cir = 1;
    if (y == fa || dep >= d[y]) continue;
    escape(y, x, dep + 1);
  }
}
int n, a, b;
int main() {
  n = read(), a = read(), b = read();
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    add(ha, x, y);
  }
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    add(hb, x, y);
  }
  dfs(b);
  dfs(b, b);
  escape(a, 0, 0);
  printf("%d\n", cir ? -1 : ans);
  return 0;
}
