#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << arg << " "; Debug(rest...); }
template<class T>ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<< ", ";out<<v.back();}out << "]";return out;}
template<class S, class T>ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

struct UF {
	vector<int> par;
	void init(int n) {
		par.resize(n); 
		for(int i = 0; i < n; i++) {
			par[i] = i;
		}
	}
	UF(int mx = 0) { init(mx); }

	int find(int x) {
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) { //x: par y: child
		x = find(x);
		y = find(y);
		if(x == y) return;
		par[y] = x;
	}
	bool same(int x, int y) { return find(x) == find(y); }
};

UF U;
int N;

vector<pi> L[MAX_N];
pi E[2][MAX_N];
set<pi> S[MAX_N];

void solve() {
	cin >> N;
	U.init(N);
	rep(k, 0, 2) {
		rep(i, 0, N - 1) {
			int a, b;
			cin >> a >> b; a--; b--;
			if(a > b) swap(a, b);
			E[k][i] = pi(a, b);
			S[k].insert(pi(a, b));
			L[a].push_back(pi(i, k));
			L[b].push_back(pi(i, k));
		}
	}

	queue<pi> que;
	for(auto w: S[0]) {
		if(S[1].count(w)) que.push(w);
	}

	while(!que.empty()) {
		pi p = que.front(); que.pop();
		int a = U.find(p.fst), b = U.find(p.sec);
		if(a == b) continue;
		if((int)L[a].size() > (int)L[b].size()) swap(a, b);
		U.unite(b, a);
		for(auto w: L[a]) {
			int id = w.fst, k = w.sec;
			S[k].erase(E[k][id]);
			E[k][id].fst = U.find(E[k][id].fst);
			E[k][id].sec = U.find(E[k][id].sec);
			if(E[k][id].fst > E[k][id].sec) swap(E[k][id].fst, E[k][id].sec);
			S[k].insert(E[k][id]);
			if(S[1 - k].count(E[k][id])) que.push(E[k][id]);
			L[b].push_back(w);
		}
		L[a].clear();
	}

	bool ok = true;
	for(int i = 0; i < N; i++) {
		if(U.find(0) != U.find(i)) ok = false;
	}
	cout << (ok ? "YES" : "NO") << "\n"; 
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 50536