#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
int n,head[201010],tot;
struct edge{
	int to,nxt;
}g[404040];
inline void made(int from,int to){
	g[++tot].to=to;g[tot].nxt=head[from];head[from]=tot;
}
int e[404040][2];
vector<int> seg[606060];
int sum[606060],sz[202020],pre[202020],tcnt,tpos[202020];
int top[202020],dep[202020],fa[202020],wson[202020];
void dfs1(int u,int faa){
	dep[u]=dep[faa]+1;fa[u]=faa;sz[u]=1;
	for (int i=head[u];i;i=g[i].nxt){
		int v=g[i].to;
		if (v==faa) continue;
		dfs1(v,u);
		sz[u]+=sz[v];
		if (sz[wson[u]]<sz[v]) wson[u]=v;
	}
}
void dfs2(int u,int tp){
	top[u]=tp;tpos[u]=++tcnt;pre[tcnt]=u;
	if (wson[u]) dfs2(wson[u],tp);
	for (int i=head[u];i;i=g[i].nxt){
		int v=g[i].to;
		if (v==fa[u]||v==wson[u]) continue;
		dfs2(v,v);
	}
}
inline void pushup(int rt){
	sum[rt]=min(sum[rt<<1],sum[rt<<1|1]);
}
int tag[606060];
inline void pushdown(int rt){
	if (tag[rt]){
		sum[rt<<1]+=tag[rt],sum[rt<<1|1]+=tag[rt];
		tag[rt<<1]+=tag[rt],tag[rt<<1|1]+=tag[rt];
		tag[rt]=0;
	}
}
bool die[202020];
#define mid ((lb+rb)>>1)
inline void _update(int rt,int lb,int rb,int l,int r,int x){
	if (lb>r||rb<l) return;
	if (lb>=l&&rb<=r) return (void)(sum[rt]++,tag[rt]++,seg[rt].push_back(x));
	pushdown(rt);
	_update(rt<<1,lb,mid,l,r,x),_update(rt<<1|1,mid+1,rb,l,r,x);
	pushup(rt);
}
inline void _clr(int rt,int lb,int rb,int l,int r){
	if (lb>r||rb<l) return;
	if (lb>=l&&rb<=r) return (void)(sum[rt]--,tag[rt]--);
	pushdown(rt);
	_clr(rt<<1,lb,mid,l,r),_clr(rt<<1|1,mid+1,rb,l,r);
	pushup(rt);
}
inline void del(int rt,int lb,int rb,int pos){
	if (lb==rb) return (void)(sum[rt]=0x3f3f3f3f);
	pushdown(rt);
	(mid>=pos?del(rt<<1,lb,mid,pos):del(rt<<1|1,mid+1,rb,pos));
	pushup(rt);
}
inline void update(int x,int y,int id){
	while (top[x]!=top[y]){
		if (dep[top[x]]<dep[top[y]]) swap(x,y);
		_update(1,1,n,tpos[top[x]],tpos[x],id);
		x=fa[top[x]];
	}
	if (dep[x]<dep[y]) swap(x,y);
	if (tpos[y]+1<=tpos[x]) _update(1,1,n,tpos[y]+1,tpos[x],id);
}
inline void clr(int x,int y){
	while (top[x]!=top[y]){
		if (dep[top[x]]<dep[top[y]]) swap(x,y);
		_clr(1,1,n,tpos[top[x]],tpos[x]);
		x=fa[top[x]];
	}
	if (dep[x]<dep[y]) swap(x,y);
	if (tpos[y]+1<=tpos[x]) _clr(1,1,n,tpos[y]+1,tpos[x]);
}
//vector<int> vic;
bool flag; 
int ttot;
void kill(int rt,int lb,int rb,int POS){
	for (;seg[rt].size()&&die[seg[rt].back()];seg[rt].pop_back());
	if (seg[rt].size()) POS=seg[rt].back();
	if (lb==rb){
		assert(POS);ttot++;
		die[POS]=1;
		clr(e[POS][0],e[POS][1]);
		del(1,1,n,lb);
		flag=1;
		return;
	}
	pushdown(rt);
	if (sum[rt<<1]==1) kill(rt<<1,lb,mid,POS);
	if (flag) return (void)(pushup(rt));
	if (sum[rt<<1|1]==1) kill(rt<<1|1,mid+1,rb,POS);
	pushup(rt);
}
signed main(){
	n=read();
	for (int i=1;i<n;i++){
		int x=read(),y=read();
		made(x,y);made(y,x);
	}
	dfs1(1,0),dfs2(1,1);
	for (int i=1;i<n;i++) e[i][0]=read(),e[i][1]=read(),update(e[i][0],e[i][1],i);
	del(1,1,n,1);
	for (;;){
		if (ttot==n-1){
			puts("YES");return 0;
		}
		flag=0;
		kill(1,1,n,0);
		if (!flag){
			puts("NO");return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 44148