#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
struct edge {
	int t,nxt;
}e[N];
int n,num;
int fa[N];
#define pii pair<int,int>
#define mk make_pair
queue<pii>q;
map<pii,int>mp;
set<int>s[N];
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
int main() {
	scanf("%d",&n);num=n;
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1,u,v;i<2*n-1;i++) {
		scanf("%d%d",&u,&v);
		s[u].insert(v),s[v].insert(u);
		mp[mk(u,v)]++,mp[mk(v,u)]++;
		if (mp[mk(u,v)]==2) q.push(mk(u,v));
	}
	while (!q.empty()) {
		pii now=q.front();q.pop();
		int u=find(now.first),v=find(now.second);
		num--;fa[v]=u;
		s[u].erase(v);
		set<int>::iterator it;
		for (it=s[v].begin();it!=s[v].end();it++) {
			int to=*it;
			if (to==u) continue;
			s[to].erase(v);
			s[u].insert(to);s[to].insert(u);
			mp[mk(u,to)]++;mp[mk(to,u)]++;
			if (mp[mk(u,to)]==2) q.push(mk(u,to));
		}
		s[v].clear();
	}
	if (num>1) puts("NO");
	else puts("YES");
}