#include<bits/stdc++.h>
using namespace std;
long long n,cnt;
long long fa[100005];
set<long long>a[100005];
struct node
{
	long long x,y;
};
bool operator <(node aa,node bb)
{
	return aa.x==bb.x?aa.y<bb.y:aa.x<bb.x;
}
queue<node>q;
map<node,long long>mp;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
void write(long long z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
	putchar(z%10+'0');
}
node bh(long long aa,long long bb)
{
	node A;
	A.x=min(aa,bb);
	A.y=max(aa,bb);
	return A;
}
int getfa(int aa)
{
	return fa[aa]==aa?aa:fa[aa]=getfa(fa[aa]);
}
int main()
{
	n=read();
	for(long long i=1;i<=n;++i) fa[i]=i;
	for(long long i=1;i<n*2-1;++i) 
	{
		long long x=read(),y=read();
		a[x].insert(y);
		a[y].insert(x);
		node aa=bh(x,y);
		if(++mp[aa]==2) cnt++,q.push(aa);
	}
	while(!q.empty())
	{
		node kk=q.front();
		q.pop();
		long long X=getfa(kk.x),Y=getfa(kk.y);
		if(X==Y) continue;
		if(a[X].size()<a[Y].size()) swap(X,Y);
		a[X].erase(Y);
		for(set<long long>::iterator it=a[Y].begin();it!=a[Y].end();++it)
		{
			long long tmp=(*it);
			if(tmp==X) continue;
			a[X].insert(tmp);
			a[tmp].erase(Y);
			a[tmp].insert(X);
			if(++mp[bh(X,tmp)]==2) cnt++,q.push(bh(X,tmp));
		}
		fa[Y]=X;
		a[Y].clear();
	}
	if(cnt==n-1) puts("YES");
	else puts("NO");
	return 0;
}