#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;

const int N = 1e5 + 10;

set<pip> c[N]; int p[N];

set<pii> eG[2], eB;
pii swp(pii x){ if (x.first < x.second) return x; else return pii(x.second, x.first); }

void insG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].insert(pip(G, e));
	c[v].insert(pip(G, e));

	if (eG[1 - G].count(e)) eB.insert(e);
	eG[G].insert(e);
}

void ersG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].erase(pip(G, e));
	c[v].erase(pip(G, e));

	eB.erase(e);
	eG[G].erase(e);
}

int findpar(int u){ return (p[u] == u ? u : p[u] = findpar(p[u])); }

void mrg(int u, int v){
	u = findpar(u), v = findpar(v);
	if (c[v].size() > c[u].size()) swap(u, v);
	p[v] = u;

	while(c[v].size()){
		pip e = *c[v].begin();
		ersG(e.first, e.second.first, e.second.second);
		if (e.second.first == v) e.second.first = u;
		if (e.second.second == v) e.second.second = u;
		insG(e.first, e.second.first, e.second.second);
	}
}

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

	int n; cin >> n;
	iota(p, p + n, 0);
	for (int k = 0; k < 2; k++)
		for (int i = 0; i < n - 1; i++){
			int u, v; cin >> u >> v; u--; v--;
			insG(k, u, v);
		}

	int cnt = 0;
	while(eB.size()){
		cnt++;
		pii e = *eB.begin(); ersG(0, e.first, e.second); ersG(1, e.first, e.second);
		mrg(e.first, e.second);
	}

	if (cnt == n - 1) cout << "YES\n";
	else cout << "NO\n";
}