#include <bits/stdc++.h>
using namespace std;
bool czy[200010], special[200010];
int bdistance[200010], ojciec[200010], ile[200010];
vector<int> red[200010], blue[200010];
int Find(int x) {
  if (ojciec[x] != x) ojciec[x] = Find(ojciec[x]);
  return ojciec[x];
}
void join(int a, int b) {
  a = Find(a);
  b = Find(b);
  if (ile[a] > ile[b]) swap(a, b);
  if (a != b) {
    ojciec[a] = b;
    ile[b] += ile[a];
  }
}
void calculate_blue(int x) {
  czy[x] = true;
  int s = (int)blue[x].size();
  for (int i = 0; i < s; ++i) {
    if (!czy[blue[x][i]]) {
      bdistance[blue[x][i]] = bdistance[x] + 1;
      calculate_blue(blue[x][i]);
    }
  }
  czy[x] = false;
}
void calculate_special(int x, int y) {
  czy[x] = true;
  int s = (int)red[x].size();
  for (int i = 0; i < s; ++i) {
    if (czy[red[x][i]]) {
      int odl =
          bdistance[x] + bdistance[red[x][i]] - 2 * bdistance[Find(red[x][i])];
      if (odl >= 3) special[x] = special[red[x][i]] = true;
    }
  }
  s = (int)blue[x].size();
  for (int i = 0; i < s; ++i) {
    if (!czy[blue[x][i]]) calculate_special(blue[x][i], x);
  }
  join(x, y);
  czy[x] = false;
}
int answer(int x, int y) {
  czy[x] = true;
  if (special[x] && bdistance[x] > y) return 1000000000;
  if (bdistance[x] <= y) return y;
  int odp = bdistance[x];
  int s = (int)red[x].size();
  for (int i = 0; i < s; ++i) {
    if (!czy[red[x][i]]) {
      odp = max(answer(red[x][i], y + 1), odp);
    }
  }
  return odp;
}
int main() {
  int n, x, y, a, b;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    red[a].push_back(b);
    red[b].push_back(a);
    ojciec[i] = i;
    ile[i] = 1;
  }
  ojciec[n] = n;
  ile[n] = 1;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    blue[a].push_back(b);
    blue[b].push_back(a);
  }
  calculate_blue(y);
  calculate_special(y, y);
  int ans = answer(x, 0);
  if (ans == 1000000000)
    puts("-1");
  else
    printf("%d", 2 * ans);
  return 0;
}
