#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#define rg register
using namespace std;
typedef long long ll;
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;char ch=getchar();int f=0;
	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;
}
struct data{
	int x,y;
	bool operator < (const data &t)const{return x==t.x?y<t.y:x<t.x;}
}tmp;
int n,x,y,t,cnt,f[maxn];
queue<data> q;
set<int> s[maxn];
map<data,int> ma;
set<int>::iterator itr;
inline int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
void input()
{
	int u,v;
	read(n);n=n+n-1;
	for(rg int i=1;i<n;i++)
	{
		read(u);read(v);
		s[u].insert(v);s[v].insert(u);
		ma[(data){u,v}]++;ma[(data){v,u}]++;
		if(ma[(data){u,v}]==2) q.push((data){u,v});
	}
	n=(n+1)>>1;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	input();
	for(rg int i=1;i<=n;i++) f[i]=i;
	while(!q.empty())
	{
		tmp=q.front();q.pop();
		x=find(tmp.x);y=find(tmp.y);
		if(s[x].size()<s[y].size()) swap(x,y);
		for(itr=s[y].begin();itr!=s[y].end();itr++)
		{
			t=*itr;
			ma[(data){y,t}]=0;ma[(data){t,y}]=0;
			ma[(data){x,t}]++;ma[(data){t,x}]++;
			if(ma[(data){x,t}]==2) q.push((data){x,t});
			s[x].insert(t);s[y].insert(x);s[t].erase(y);
		}
		f[y]=x;s[y].clear();
	}
	for(rg int i=1;i<=n&&cnt<=1;i++) if(find(i)==i) cnt++;
	if(cnt==1) puts("YES");
	else puts("NO");
	return 0;
}