#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if
#define Lsn (x<<1)
#define Rsn (x<<1|1)
#define Mid ((L+R)>>1)

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;
const int oo=(1<<30)-1;

struct edge{
	int x,y;
} e[N],e2[N];

struct Edge{
	int y,id,nxt;
} E[N*2];
int las[N],fa[N],sz[N],dep[N],id[N],son[N],top[N],Sum[N],Xor[N],pt[N],edg[N];
int n,cnt,x,y,num,tot,Ql,Qr;

void Link(int x,int y,int id){
	E[cnt]=(Edge){y,id,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,id,las[y]};las[y]=cnt++;
}
void dfs(int x){
	sz[x]=1;
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa[x]){
			fa[y]=x;
			edg[y]=E[i].id;
			dep[y]=dep[x]+1;
			dfs(y);
			sz[x]+=sz[y];
			if (sz[y]>sz[son[x]]) son[x]=y;
		}
}
void dfs(int x,int anc){
	id[x]=++tot;
	pt[tot]=x;
	top[x]=anc;
	if (son[x]) dfs(son[x],anc);
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa[x]&&y!=son[x]){
			dfs(y,y);
		}
}
void Dfs(int x){
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa[x]){
			Dfs(y);
			Sum[x]+=Sum[y];
			Xor[x]^=Xor[y];
		}
}
int LCA(int x,int y){
	int a=top[x],b=top[y];
	while (a!=b){
		if (dep[a]>dep[b]) swap(a,b),swap(x,y);
		y=fa[b],b=top[y];
	}
	return dep[x]<dep[y]?x:y;
}

int xo[N*4],plu[N*4];
pii mn[N*4];

void Plus(int x,int v){
	plu[x]+=v;
	mn[x].fi+=v;
}
void Down(int x){
	if (plu[x]){
		Plus(Lsn,plu[x]);
		Plus(Rsn,plu[x]);
		plu[x]=0;
	}
}
void Build(int x,int L,int R){
	if (L==R){
		mn[x]=mp(Sum[pt[L]],L);
		return;
	}
	Build(Lsn,L,Mid);
	Build(Rsn,Mid+1,R);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}
void Change(int x,int L,int R,int Qx){
	if (L==R){
		mn[x]=mp(oo,0);
		return;
	}
	Down(x);
	Qx<=Mid?Change(Lsn,L,Mid,Qx):Change(Rsn,Mid+1,R,Qx);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}
void Query(int x,int L,int R,int Qx){
	num^=xo[x];
	if (L==R) return;
	Qx<=Mid?Query(Lsn,L,Mid,Qx):Query(Rsn,Mid+1,R,Qx);
}
void Modify(int x,int L,int R){
	if (Ql<=L&&R<=Qr){
		Plus(x,-1);
		xo[x]^=num;
		return;
	}
	Down(x);
	if (Ql<=Mid) Modify(Lsn,L,Mid);
	if (Qr>Mid) Modify(Rsn,Mid+1,R);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}
void gao(int x,int y){
	int a=top[x],b=top[y];
	while (a!=b){
		if (dep[a]>dep[b]) swap(a,b),swap(x,y);
		Ql=id[b],Qr=id[y];
		Modify(1,1,n);
		y=fa[b],b=top[y];
	}
	Ql=id[x],Qr=id[y];
	if (Ql>Qr) swap(Ql,Qr);
	if (++Ql<=Qr) Modify(1,1,n);
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN();
	For(i,1,n){
		x=IN(),y=IN();
		Link(x,y,i);
		e[i]=(edge){x,y};
	}
	dfs(1);
	dfs(1,1);
	For(i,1,n){
		x=IN(),y=IN();
		int z=LCA(x,y);
		e2[i]=(edge){x,y};
		Sum[x]++;
		Sum[y]++;
		Sum[z]-=2;
		Xor[x]^=i;
		Xor[y]^=i;
	}
	Dfs(1);
	Sum[1]=oo;
	Build(1,1,n);
	For(t,1,n){
		pii m;
		for(;;){
			m=mn[1];
			if (m.fi>1){
				puts("NO");
				return 0;
			}
			if (m.fi==1) break;
			Change(1,1,n,m.se);
		}
		assert(pt[m.se]!=1);
		num=Xor[pt[m.se]];
		Query(1,1,n,m.se);
		gao(e2[num].x,e2[num].y);
	}
	puts("YES");
}

Measured memory_bytes: 18944