//besmellah
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

const int maxn = 1e5 + 5, inf = 2e9;
int seg[4 * maxn], mn[4 * maxn], lazy[4 * maxn], V[maxn], T, U[maxn], st[maxn], up[maxn], sz[maxn], par[maxn], h[maxn];
vector <int> adj[maxn], vec[4 * maxn];
bitset <maxn> mark;
int n;

//inline bool cmp(int a, int b) {
//	return sz[a] > sz[b];
//}

inline void relax(int id) {
	int x = lazy[id];
	lazy[id] = 0;
	mn[2 * id + 0] += x;
	lazy[2 * id + 0] += x;
	mn[2 * id + 1] += x;
	lazy[2 * id + 1] += x;
}

void build(int id, int L, int R) {
	seg[id] = L;
	if (R == L + 1)
		return;
	int mid = (L + R) / 2;
	build(2 * id + 0, L, mid);
	build(2 * id + 1, mid, R);
}

void add(int id, int L, int R, int l, int r, int x) {
	if (R <= l || r <= L)
		return;
	if (L >= l && R <= r) {
		mn[id] += x;
		lazy[id] += x;
		return;
	}
	relax(id);
	int mid = (L + R) / 2;
	add(2 * id + 0, L, mid, l, r, x);
	add(2 * id + 1, mid, R, l, r, x);
	mn[id] = min(mn[2 * id], mn[2 * id + 1]);
	if (mn[id] == mn[2 * id + 0])
		seg[id] = seg[2 * id + 0];
	else
		seg[id] = seg[2 * id + 1];
}

void push(int id, int L, int R, int l, int r, int x) {
	if (R <= l || r <= L)
		return;
	if (L >= l && R <= r) {
		vec[id].push_back(x);
		return;
	}
	int mid = (L + R) / 2;
	push(2 * id + 0, L, mid, l, r, x);
	push(2 * id + 1, mid, R, l, r, x);
}

int back(int id, int L, int R, int idx) {
	if (idx < L || idx >= R) {
		return 0;
	}
	while (vec[id].size() && mark[vec[id].back()])
		vec[id].pop_back();
	if (vec[id].size())
		return vec[id].back();
	int mid = (L + R) / 2;
	return max(back(2 * id + 0, L, mid, idx), back(2 * id + 1, mid, R, idx));
}

void getsz(int v) {
	sz[v] = 1;
	for (int u: adj[v]) {
		if (u != par[v]) {
			par[u] = v;
			h[u] = h[v] + 1;
			getsz(u);
			sz[v] += sz[u];
		}
	}
}

void dfs(int v) {
	st[v] = T++;
	bool heavy = 1;
	int mx = 0, ans = 0;
	for (int i = 0; i < adj[v].size(); i++) {
		int u = adj[v][i];
		if (u != par[v] && sz[u] > mx) {
			mx = sz[u];
			ans = i;
		}
	}
	for (int i = ans; i; i--)
		swap(adj[v][i - 1], adj[v][i]);
	for (auto u: adj[v]) {
		if (u == par[v])
			continue;
		if (heavy) {
			heavy = 0;
			up[u] = up[v];
		}
		else {
			up[u] = u;
		}
		dfs(u);
	}
}

inline void add(int v, int u, int i) {
	while (up[v] != up[u]) {
		if (h[up[v]] < h[up[u]]) {
			swap(v, u);
		}
		add(1, 0, n, st[up[v]], st[v] + 1, +1);
		push(1, 0, n, st[up[v]], st[v] + 1, i);
		v = par[up[v]];
	}
	if (v == u)
		return;
	if (h[v] < h[u])
		swap(v, u);
	add(1, 0, n, st[u] + 1, st[v] + 1, +1);
	push(1, 0, n, st[u] + 1, st[v] + 1, i);
}

inline void rem(int v, int u, int i) {
	mark[i] = 1;
	while (up[v] != up[u]) {
		if (h[up[v]] < h[up[u]]) {
			swap(v, u);
		}
		add(1, 0, n, st[up[v]], st[v] + 1, -1);
		v = par[up[v]];
	}
	if (v == u)
		return;
	if (h[v] < h[u])
		swap(v, u);
	add(1, 0, n, st[u] + 1, st[v] + 1, -1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	par[0] = -1;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	getsz(0);
	dfs(0);
	build(1, 0, n);
	add(1, 0, n, 0, 1, inf);
	for (int i = 0; i < n - 1; i++) {
		cin >> V[i] >> U[i];
		V[i]--;
		U[i]--;
		add(V[i], U[i], i);
	}
	for (int i = 0; i < n - 1; i++) {
		if (mn[1] != 1) {
//			cout << mn[1] << ' ' << i << endl;
			cout << "NO";
			return 0;
		}
		int e = back(1, 0, n, seg[1]);
//		cout << e << endl;
		add(1, 0, n, seg[1], seg[1] + 1, inf);
		rem(V[e], U[e], e);
	}
	cout << "YES";
}


Measured memory_bytes: 40900