#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

const int MAX_LG = 20;
const int MAX_N = 2e5 + 5;
const int INF = 1e9 + 5;

namespace Ender {
  vector<int> adj [MAX_N];
  int par [MAX_N];
  int lvl [MAX_N];
  int lend [MAX_N], rend [MAX_N];
  int jmp [MAX_N][MAX_LG];
  
  void add_edge (int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int lca (int u, int v) {
    if (lvl[u] < lvl[v]) swap(u, v);

    int diff = lvl[u] - lvl[v];
    for (int i = 0; i < MAX_LG; i++) {
      if (diff & 1 << i) {
        u = jmp[u][i];
      }
    }

    if (u == v) return u;

    for (int i = MAX_LG - 1; i >= 0; i--) {
      if (jmp[u][i] != jmp[v][i]) {
        u = jmp[u][i];
        v = jmp[v][i];
      }
    }
    return jmp[u][0];
  }

  int dist (int u, int v) {
    return lvl[u] + lvl[v] - 2 * lvl[lca(u, v)];
  }

  int anc_at (int u, int l) {
    int diff = lvl[u] - l;

    for (int i = 0; i < MAX_LG; i++) {
      if (diff & 1 << i) {
        u = jmp[u][i];
      }
    }
    return u;
  }
  
  void dfs (int u, int p, int &cur) {
    jmp[u][0] = p;
    for (int i = 1; i < MAX_LG; i++) {
      jmp[u][i] = jmp[jmp[u][i - 1]][i - 1];
    }
    
    cur++;
    lend[u] = cur;
    lvl[u] = lvl[p] + 1;
    par[u] = p;

    for (int nxt : adj[u]) {
      if (nxt != p) {
        dfs(nxt, u, cur);
      }
    }
    
    rend[u] = cur;
  }
  
  void build () {
    int cur = 0;
    dfs(1, 0, cur);
  }
  
  bool islong (int u, int v) {
    if (u == v) return false; // dist 0
    if (par[u] == v || par[v] == u) return false; // dist 1
    if (par[par[u]] == v || par[par[v]] == u) return false; // dist 2, grandparent
    if (par[u] == par[v]) return false; // dist 2, cousin
    return true;
  }

  int towards (int cur, int tar) {
    if (cur == tar) return cur;
    if (lend[tar] < lend[cur] || rend[cur] < lend[tar]) return par[cur];
    return anc_at(tar, lvl[cur] + 1);
  }
}

namespace Delayer {
  vector<int> adj [MAX_N];
  int special [MAX_N];
  
  vector<pair<int, int>> edges;
  
  void add_edge (int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges.push_back(make_pair(u, v));
  }

  void build () {
    for (auto pr : edges) {
      if (Ender::islong(pr.first, pr.second)) {
        special[pr.first] = 1;
        special[pr.second] = 1;
      }
    }
  }
}

int dpt = 0;
int play (int d, int dl, int e) {
  /*
  for (int i = 0; i < 2 * dpt; i++) {
    cout << " ";
  }
  cout << d << " " << e << endl;
  */
  //  cerr << d << " " << dl << " " << e << endl;
  
  if (e == d) return 0;
  if (Delayer::special[d]) return INF;
  
  int ans = 2 * Ender::dist(d, e);
  for (int nxt : Delayer::adj[d]) {
    if (nxt != dl) {
      dpt += 2;
      ans = max(ans, 2 + play(nxt, d, Ender::towards(e, nxt)));
      dpt -= 2;
    }
  }
  return ans;
}

int main () {
  ios::sync_with_stdio(false);
  
  int n, x, y;
  cin >> n >> x >> y;

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;

    Delayer::add_edge(u, v);
  }

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;

    Ender::add_edge(u, v);
  }

  Ender::build();
  Delayer::build();
  
  int ans = play(x, -1, y);
  if (ans >= INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 57296