#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class Lowest_Common_Ancestor {
	vector<int>depth;
	vector<vector<int>>parent;
	vector<vector<int>>edge;
	int height = 0;
	int node;
public:
	Lowest_Common_Ancestor(int num) {
		num++;
		node = num;
		while (num) {
			height++;
			num /= 2;
		}
		parent.resize(height);
		edge.resize(node);
		depth.resize(node);
		for (int i = 0; i < height; i++)parent[i].resize(node);
	}
	void Add_Edge(int a, int b) {
		edge[a].push_back(b);
		edge[b].push_back(a);
		return;
	}
	void Update(int rtnode) {
		queue<int>QQ;
		for (int i = 0; i < node; i++) depth[i] = INT_MAX;
		depth[rtnode] = 0;
		QQ.push(rtnode);
		while (!QQ.empty()) {
			int c = QQ.front();
			for (auto i : edge[c]) {
				if (depth[i] > depth[c] + 1) {
					depth[i] = depth[c] + 1;
					QQ.push(i);
				}
			}
			QQ.pop();
		}
		parent[0][rtnode] = -1;
		for (int i = 1; i < node; i++) {
			for (auto j : edge[i]) {
				if (depth[i] - 1 == depth[j]) {
					parent[0][i] = j;
					break;
				}
			}
		}
		for (int i = 0; i < height - 1; i++) {
			for (int j = 0; j < node; j++) {
				if (parent[i][j] < 0)parent[i + 1][j] = -1;
				else parent[i + 1][j] = parent[i][parent[i][j]];
			}
		}
		return;
	}
	int LCA(int u, int v) {
		if (depth[u] > depth[v])swap(u, v);
		for (int i = 0; i < height; i++) {
			if ((depth[v] - depth[u]) >> i & 1) {
				v = parent[i][v];
			}
		}
		if (u == v)return u;
		for (int i = height - 1; i >= 0; i--) {
			if (parent[i][v] != parent[i][u]) {
				u = parent[i][u];
				v = parent[i][v];
			}
		}
		return parent[0][u];
	}
	int Dist(int u, int v) {
		return depth[u] + depth[v] - depth[LCA(u, v)] * 2;
	}
};

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> L >> R;
	vector<vector<int>>edge(N + 1);
	Lowest_Common_Ancestor lca(N);
	for (int i = 1; i < N; i++) {
		cin >> H >> W;
		edge[H].push_back(W);
		edge[W].push_back(H);
	}
	vector<vector<int>>wedge(N + 1);
	for (int i = 1; i < N; i++) {
		cin >> H >> W;
		wedge[H].push_back(W);
		wedge[W].push_back(H);
		lca.Add_Edge(H, W);
	}
	lca.Update(R);
	vector<int>safe(N + 1);
	for (int i = 1; i <= N; i++) {
		for (auto j : edge[i]) {
			if (lca.Dist(i, j) > 2)safe[i] = safe[j] = 1;
		}
	}
	vector<int>depth(N + 1, MOD);
	Calculate_Depth(wedge, depth, R);
	vector<int>dist(N + 1, MOD);
	dist[L] = 0;
	queue<int>Q;
	Q.push(L);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		if (safe[cn]) {
			cout << -1 << endl;
			return 0;
		}
		for (auto i : edge[cn]) {
			auto dis = lca.Dist(i, cn);
			if (dis > 2)continue;
			if (dist[i] > dist[cn] + 1 ) {
				if (dist[cn] + 1 < depth[i]) {
					dist[i] = dist[cn] + 1;
					Q.push(i);
				}
				else if (dist[cn] + 1 == depth[i]) {
					dist[i] = dist[cn] + 1;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (dist[i] == MOD)continue;
		ans = max(ans, depth[i]);
	}
	cout << (ans << 1) << endl;
	return 0;
}

Measured memory_bytes: 53108