#include <bits/stdc++.h>

#define fi first
#define se second
#define mkp std::make_pair

typedef std::pair <int, int> pii;

const int kN = 1e5 + 5;

int n, fa[kN];
std::queue <pii> que;
std::set <int> E[kN];
std::map <int, int> cnt[kN];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
bool Merge(int u, int v) {
	u = Find(u), v = Find(v);
	if(u == v) return false;
	if(E[u].size() < E[v].size()) std::swap(u, v);
	for(auto i : E[v]) if(i != u) {
		E[u].insert(i); ++cnt[u][i];
		if(cnt[u][i] >= 2) que.push(mkp(u, i));
		E[i].erase(v); --cnt[i][v];
		E[i].insert(u); ++cnt[i][u];
	//	if(cnt[i][u] >= 2) que.push(mkp(u, i));
	}
	fa[v] = u;
	return true;
}
void Print() {
	for(int i = 1; i <= n; ++i) if(i == Find(i)) {
		printf("Cur[%d] = ", i);
		for(auto j : E[i]) printf("%d ", j);
		printf("\n");
	}
}
bool Solve() {
	int res = n - 1;
//	Print();
	while(!que.empty()) {
		pii cur = que.front(); que.pop();
	//	printf("%d %d\n", cur.fi, cur.se);
	//	fflush(stdout);
		res -= Merge(cur.fi, cur.se);
	//	Print();
	}
	return !res;
}

int main() {
//	freopen("e.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) fa[i] = i;
	for(int i = 1; i < 2 * n - 1; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		E[u].insert(v); E[v].insert(u);
		++cnt[u][v]; ++cnt[v][u];
		if(cnt[u][v] >= 2) {
			que.push(mkp(u, v));
		}
	}
	printf(Solve() ? "YES\n" : "NO\n");
	return 0; 
}