#include <cstdio>
#include <set>
int N, head[100001], next[199999], to[199999], E, fa[100001], ref[100001], left[100001], right[100001], dep[100001], top[100001], son[100001];
void DFS()
{
	static int q[100001], ue[100001], size[100001];
	int H = 0, T = 1, u;
	q[1] = 1;
	while (H < T)
		for (int e = head[u = q[++H]]; e; e = next[e])
			if (to[e] != fa[u])
			{
				fa[q[++T] = to[e]] = u;
				dep[to[e]] = dep[u] + 1;
			}
	for (int i = 1; i <= N; i++)
		size[i] = 1;
	for (int i = N; i > 1; i--)
	{
		size[fa[q[i]]] += size[q[i]];
		if (size[q[i]] > size[son[fa[q[i]]]])
			son[fa[q[i]]] = q[i];
	}
	int D = 1, TIME = 1;
	q[1] = 1;
	ue[1] = head[1];
	ref[left[1] = right[1] = 1] = 1;
	top[1] = 1;
	while (D)
		if (son[q[D]] && !left[son[q[D]]])
		{
			int To = son[q[D]];
			ref[left[To] = right[To] = ++TIME] = To;
			top[To] = top[q[D]];
			q[++D] = To;
			ue[D] = head[To];
		}
		else
		{
			while (ue[D] && (to[ue[D]] == son[q[D]] || to[ue[D]] == fa[q[D]]))
				ue[D] = next[ue[D]];
			if (ue[D])
			{
				int To = to[ue[D]];
				ue[D] = next[ue[D]];
				ref[left[To] = right[To] = ++TIME] = To;
				top[To] = To;
				q[++D] = To;
				ue[D] = head[To];
			}
			else
			{
				if (D > 1)
					right[q[D - 1]] = right[q[D]];
				D--;
			}
		}
}
int MIN[262144], ADD[262144];
std::set < std::pair < int, int > > CVR[262144];
inline void down(int p)
{
	if (ADD[p])
	{
		MIN[p << 1] += ADD[p];
		ADD[p << 1] += ADD[p];
		MIN[p << 1 | 1] += ADD[p];
		ADD[p << 1 | 1] += ADD[p];
		ADD[p] = 0;
	}
}
void P(int p, int l, int r, int L, int R, std::pair < int, int > w, int d)
{
	if (L <= l && r <= R)
	{
		MIN[p] += d;
		ADD[p] += d;
		if (d == 1)
			CVR[p].insert(w);
		else
			CVR[p].erase(w);
		return;
	}
	int m = l + r >> 1;
	down(p);
	if (L <= m)
		P(p << 1, l, m, L, R, w, d);
	if (R > m)
		P(p << 1 | 1, m + 1, r, L, R, w, d);
	MIN[p] = std::min(MIN[p << 1], MIN[p << 1 | 1]);
}
void Cover(int x, int y, int d)
{
	int u = x, v = y;
	while (top[u] != top[v])
		if (dep[top[u]] > dep[top[v]])
		{
			P(1, 2, N, left[top[u]], left[u], { x, y }, d);
			u = fa[top[u]];
		}
		else
		{
			P(1, 2, N, left[top[v]], left[v], { x, y }, d);
			v = fa[top[v]];
		}
	if (dep[u] > dep[v])
		P(1, 2, N, left[v] + 1, left[u], { x, y }, d);
	if (dep[u] < dep[v])
		P(1, 2, N, left[u] + 1, left[v], { x, y }, d);
}
std::pair < int, std::pair < int, int > > FindMin()
{
	std::pair < int, int > path(0, 0);
	int p = 1, l = 2, r = N;
	if (!CVR[p].empty())
		path = *CVR[p].begin();
	while (l < r)
	{
		int m = l + r >> 1;
		down(p);
		if (MIN[p] == MIN[p << 1])
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
		if (!CVR[p].empty())
			path = *CVR[p].begin();
	}
	return { l, path };
}
void MakeInf(int x)
{
	int p = 1, l = 2, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		down(p);
		if (x <= m)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	MIN[p] = 1000000000;
	while (p > 1)
	{
		p >>= 1;
		MIN[p] = std::min(MIN[p << 1], MIN[p << 1 | 1]);
	}
}
int main()
{
	scanf("%d", &N);
	for (int i = 1, u, v; i < N; i++)
	{
		scanf("%d%d", &u, &v);
		next[++E] = head[u], to[E] = v, head[u] = E;
		next[++E] = head[v], to[E] = u, head[v] = E;
	}
	DFS();
	for (int i = 1, u, v; i < N; i++)
	{
		scanf("%d%d", &u, &v);
		Cover(u, v, 1);
	}
	for (int Time = N - 1; Time--; )
	{
		if (MIN[1] != 1)
		{
			puts("NO");
			return 0;
		}
		std::pair < int, std::pair < int, int > > G = FindMin();
		MakeInf(G.first);
		Cover(G.second.first, G.second.second, -1);
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 96384