#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for(int i = (s), mi = (t); i <= mi; i++)
#define dwn(i, s, t) for(int i = (s), mi = (t); i >= mi; i--)

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 100010
#define maxm 200010
#define oo 2147483647
#define pii pair <int, int>
#define x first
#define y second
#define mp(x, y) make_pair(x, y)

int n, m, head[maxn], nxt[maxm], to[maxm];
pii es[maxn];

void AddEdge(int a, int b) {
	to[++m] = b; nxt[m] = head[a]; head[a] = m;
	swap(a, b);
	to[++m] = b; nxt[m] = head[a]; head[a] = m;
	return ;
}

int fa[maxn], son[maxn], dep[maxn], siz[maxn], top[maxn], dfn[maxn], clo;
void build(int u) {
	siz[u] = 1;
	for(int e = head[u]; e; e = nxt[e]) if(to[e] != fa[u]) {
		fa[to[e]] = u;
		dep[to[e]] = dep[u] + 1;
		build(to[e]);
		siz[u] += siz[to[e]];
		if(!son[u] || siz[son[u]] < siz[to[e]]) son[u] = to[e];
	}
	return ;
}
void gett(int u, int tp) {
	top[u] = tp; dfn[u] = ++clo;
	if(son[u]) gett(son[u], tp);
	for(int e = head[u]; e; e = nxt[e]) if(to[e] != fa[u] && to[e] != son[u]) gett(to[e], to[e]);
	return ;
}

bool ava[maxn];
namespace Sgt {
	int minv[maxn<<2], addv[maxn<<2];
	set <int> eid[maxn<<2];
	
	void pushdown(int o, int l, int r) {
		if(l == r || !addv[o]) return (void)(addv[o] = 0);
		int lc = o << 1, rc = lc | 1;
		addv[lc] += addv[o]; minv[lc] += addv[o];
		addv[rc] += addv[o]; minv[rc] += addv[o];
		addv[o] = 0;
		return ;
	}
	
	void Add(int o, int l, int r, int ql, int qr, int id) {
		pushdown(o, l, r);
		if(ql <= l && r <= qr) eid[o].insert(id), addv[o]++, minv[o]++;
		else {
			int mid = l + r >> 1, lc = o << 1, rc = lc | 1;
			if(ql <= mid) Add(lc, l, mid, ql, qr, id);
			if(qr > mid) Add(rc, mid + 1, r, ql, qr, id);
			minv[o] = min(minv[lc], minv[rc]);
		}
		return ;
	}
	
	void clearZero(int o, int l, int r) {
		pushdown(o, l, r);
		if(minv[o]) return ;
		if(l == r) minv[o] = oo;
		else {
			int mid = l + r >> 1, lc = o << 1, rc = lc | 1;
			if(minv[lc] == minv[o]) clearZero(lc, l, mid);
			if(minv[rc] == minv[o]) clearZero(rc, mid + 1, r);
			minv[o] = min(minv[lc], minv[rc]);
		}
		return ;
	}
	
	int getEid(int o, int l, int r, int nowid) {
		pushdown(o, l, r);
		if(!nowid) {
			set <int> :: iterator it;
			for(it = eid[o].begin(); it != eid[o].end();) {
				if(!ava[*it]) eid[o].erase(it++);
				else break;
			}
			if(it != eid[o].end()) nowid = *it;
		}
		if(l == r) return nowid;
		int mid = l + r >> 1, lc = o << 1, rc = lc | 1;
		if(minv[lc] == 1) return getEid(lc, l, mid, nowid);
		return getEid(rc, mid + 1, r, nowid);
	}
	
	void Erase(int o, int l, int r, int ql, int qr) {
		pushdown(o, l, r);
		if(ql <= l && r <= qr) addv[o]--, minv[o]--;
		else {
			int mid = l + r >> 1, lc = o << 1, rc = lc | 1;
			if(ql <= mid) Erase(lc, l, mid, ql, qr);
			if(qr > mid) Erase(rc, mid + 1, r, ql, qr);
			minv[o] = min(minv[lc], minv[rc]);
		}
		return ;
	}
}

void addChain(int a, int b, int eid) {
	ava[eid] = 1;
	while(top[a] != top[b]) {
		if(dep[top[a]] < dep[top[b]]) swap(a, b);
		Sgt::Add(1, 1, n, dfn[top[a]], dfn[a], eid);
		a = fa[top[a]];
	}
	if(dep[a] > dep[b]) swap(a, b);
	Sgt::Add(1, 1, n, dfn[a] + 1, dfn[b], eid);
	return ;
}
void delChain(int a, int b, int eid) {
	ava[eid] = 0;
	while(top[a] != top[b]) {
		if(dep[top[a]] < dep[top[b]]) swap(a, b);
		Sgt::Erase(1, 1, n, dfn[top[a]], dfn[a]);
		a = fa[top[a]];
	}
	if(dep[a] > dep[b]) swap(a, b);
	Sgt::Erase(1, 1, n, dfn[a] + 1, dfn[b]);
	return ;
}

int main() {
	n = read();
	rep(i, 1, n - 1) {
		int a = read(), b = read();
		AddEdge(a, b);
	}
	rep(i, 1, n - 1) {
		int a = read(), b = read();
		es[i] = mp(a, b);
	}
	
	build(1); gett(1, 1);
	rep(i, 1, n - 1) addChain(es[i].x, es[i].y, i);
	int rest = n - 1;
	while(Sgt::minv[1] <= 1) {
		if(!Sgt::minv[1]) Sgt::clearZero(1, 1, n);
		if(Sgt::minv[1] > 1) break;
		int nid = Sgt::getEid(1, 1, n, 0);
		delChain(es[nid].x, es[nid].y, nid); rest--;
	}
	
	if(rest) puts("NO"); else puts("YES");
	
	return 0;
}

Measured memory_bytes: 129024