#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<unordered_map>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 100010;
const int INF = 2147483600;

#define fr first
#define sc second
int N; int Node[MAXN<<1],Next[MAXN<<1],Root[MAXN+1],cnt;
multiset<int> S[MAXN+1]; int fa[MAXN+1];
queue<pair<int,int> > que;
inline int find(int x){
	return (x==fa[x]?x:(fa[x]=find(fa[x])));
}
pair<int,int> sta[MAXN+1];int top;
unordered_map<int,int> mp[MAXN+1];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); 
	for(int i=1;i<=N;i++) fa[i]=i;
	for(int i=1;i<=2*N-2;i++){
		int u=read(),v=read();
		S[u].insert(v);
		S[v].insert(u);
		mp[u][v]++; mp[v][u]++;
		if(mp[u][v]==2) que.push(make_pair(u,v)),sta[++top]=make_pair(u,v);
		if(mp[u][v]>2){
			puts("NO"); return 0;
		} 
	} int d=0;
	for(int i=1;i<=top;i++){
			mp[sta[i].fr][sta[i].sc]=mp[sta[i].sc][sta[i].fr]=0;
			S[sta[i].fr].erase(S[sta[i].fr].find(sta[i].sc));
			S[sta[i].sc].erase(S[sta[i].sc].find(sta[i].fr));
		}
	while(!que.empty()){
		pair<int,int> k=que.front(); ++d; que.pop();
		int u=find(k.fr),v=find(k.sc);
		if(S[u].size()<S[v].size()) swap(u,v); int last=find(v);
		fa[find(v)]=find(u); top=0;
		multiset<int>::iterator it=S[v].begin();
		while(it!=S[v].end()){
			if(find(*it)==find(u)) {++it;continue;}
			S[u].insert(*it);
			mp[last][*it]=mp[*it][last]=0;
			mp[*it][find(u)]++;
			mp[find(u)][*it]++;
			S[*it].erase(S[*it].find(last));
			S[*it].insert(find(u));
			if(mp[find(u)][*it]==2) que.push(make_pair(find(u),(*it))),sta[++top]=make_pair(find(u),(*it));
			if(mp[find(u)][*it]>2) {
				puts("NO"); return 0;
			}
			++it;
		} 
		for(int i=1;i<=top;i++){
			mp[sta[i].fr][sta[i].sc]=mp[sta[i].sc][sta[i].fr]=0;
			S[sta[i].fr].erase(S[sta[i].fr].find(sta[i].sc));
			S[sta[i].sc].erase(S[sta[i].sc].find(sta[i].fr));
		}
		S[v].clear();
	} if(d==N-1) puts("YES");
	else puts("NO");
	return 0;
}
