#include <bits/stdc++.h>
#define rg register
#define mk(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,x,y,v,lim,f[maxn];
map<ll,int> ma;
queue<pii> q;
set<int> s[maxn];
set<int>::iterator itr;
inline int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
inline ll getid(int x,int y){return x<y?(ll)x*n+y:(ll)y*n+x;}
int link(int x,int y)
{
	s[x].insert(y);s[y].insert(x);
	ll tmp=getid(x,y);
	int t=(++ma[tmp]);
	if(t==2) q.push(mk(x,y));
	if(t==3){puts("NO");exit(0);}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	read(n);lim=n-1<<1;
	for(rg int i=1;i<=n;i++) f[i]=i;
	for(rg int i=1;i<=lim;i++)
	{
		read(x);read(y);
		link(x,y);
	}
	for(rg int i=1;i<n;i++)
	{
		while(1)
		{
			if(q.empty()){puts("NO");return 0;}
			x=q.front().first;y=q.front().second;q.pop();
			x=find(x);y=find(y);
			if(x^y) break;
		}
		if(s[x].size()>s[y].size()) swap(x,y);
		f[x]=y;s[y].erase(x);ma.erase(getid(x,y));
		for(itr=s[x].begin();itr!=s[x].end();++itr)
		{
			v=find(*itr);
			if(v==y) continue;
			ma.erase(getid(v,x));
			s[v].erase(x);
			link(y,v);
		}
		s[x].clear();
	}
	puts("YES");
	return 0;
}