#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug
#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 200010;

vector<int> e[2][MAXN];
int n, X, Y, dad[MAXN], sp[MAXN], dist[MAXN], sol;
bool infi;

void dfs(int t, int x, int par) {
  dad[x] = par;
  for (int y : e[t][x])
    if (y != par) {
      dist[y] = dist[x] + 1;
      dfs(t, y, x);
    }
}

void solve(int x, int par, int d) {
  if (sp[x]) infi = true;
  sol = max(sol, 2 * dist[x]);
  for (int y : e[0][x]) {
    TRACE(x _ y _ d _ dist[y]);
    if (y != par && dist[y] > d + 1)
      solve(y, x, d + 1);
  }
}

int main(void) {
  scanf("%d %d %d",&n,&X,&Y);
  --X; --Y;
  REP(t, 2) REP(i, n - 1) {
    int a, b;
    scanf("%d %d",&a,&b);
    --a; --b;
    e[t][a].push_back(b);
    e[t][b].push_back(a);
  }

  dfs(1, Y, -1);

  REP(a, n)
    for (int b : e[0][a]) {
      bool lng = true;
      if (dad[a] == b) lng = false;
      if (dad[b] == a) lng = false;
      if (dad[a] == dad[b]) lng = false;
      if (dad[a] != -1 && dad[dad[a]] == b) lng = false;
      if (dad[b] != -1 && dad[dad[b]] == a) lng = false;
      if (lng) sp[a] = sp[b] = 1;
    }

  REP(x, n) TRACE(x _ sp[x]);

  solve(X, -1, 0);
  if (infi)
    sol = -1;
  
  printf("%d\n",sol);
  
  return 0;
}
