#pragma region
#ifndef M207
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#endif
#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define uint unsigned int
#define ull unsigned long long
#define solid const auto &
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define gm int mid((l+r)/2)
#define space putchar(' ')
#define enter putchar('\n')
#define rd() ({ri t;in(t);t;})
#define Size(x) ((int)x.size())
#define mem(x,y) memset(x,y,sizeof(x))
template<class T>il void in(T &x)
{
	x=0; char c=getchar(); bool f=0;
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
	f?x=-x:0;
}
template<class T>il void out(T x,const char c='\n')
{
	static short st[30]; short m=0;
	if(x<0) putchar('-'),x=-x;
	do st[++m]=x%10,x/=10; while(x);
	while(m) putchar(st[m--]|'0');
	putchar(c);
}
template<class T>il void err(const T &x,const char c='\n') {cerr<<x<<c;}
template<class T,class ...Args>il void in(T &x,Args &...args) {in(x); in(args...);}
template<class T,class ...Args>il void out(const T &x,const Args &...args) {out(x,' '); out(args...);}
template<class T,class ...Args>il void err(const T &x,const Args &...args) {err(x,' '); err(args...);}
template<class T>il void prt(T a[],int n) {for(ri i=0; i<n; ++i) out(a[i],i==n-1?'\n':' ');}
template<class T>il void clr(T a[],int n) {memset(a,0,sizeof(T)*n);}
template<class T>il void clr(T *a,T *b) {memset(a,0,sizeof(T)*(b-a));}
template<class T>il bool ckmax(T &a,const T &b) {return a<b?a=b,1:0;}
template<class T>il bool ckmin(T &a,const T &b) {return a>b?a=b,1:0;}
namespace MOD_CALC
{
const int md=1e9+7,inv2=(md+1)/2;
il int add(const int a,const int b) {return a+b>=md?a+b-md:a+b;}
il int sub(const int a,const int b) {return a-b<0?a-b+md:a-b;}
il int mul(const int a,const int b) {return (LL)a*b%md;}
il void inc(int &a,const int b) {(a+=b)>=md?a-=md:0;}
il void dec(int &a,const int b) {(a-=b)<0?a+=md:0;}
il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=mul(a,a)) if(b&1) r=mul(r,a); return r;}
il int qpow(int a,int b,const int p) {int r=1; for(; b; b>>=1,a=(LL)a*a%p) if(b&1) r=(LL)r*a%p; return r;}
il int mdinv(const int a) {return qpow(a,md-2);}
template<class ...Args>il int add(const int a,const int b,const Args &...args) {return add(add(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
} using namespace MOD_CALC;
namespace i207M
{
#pragma endregion
#define N 100005
#define M N*4
#define ls (x<<1)
#define rs (x<<1|1)
const int rt=1,inf=1e9;
pii mn[M];
int laz[M],xt[M];
il void up(int x)
{
	mn[x]=min(mn[ls],mn[rs]);
}
il void give(int x,int v1,int v2)
{
	mn[x].fi+=v1,laz[x]+=v1,xt[x]^=v2;
}
il void down(int x)
{
	if(laz[x]||xt[x])
	{
		give(ls,laz[x],xt[x]),give(rs,laz[x],xt[x]);
		laz[x]=xt[x]=0;
	}
}
bool zer[N];
void build(int x,int l,int r)
{
	if(l==r)
	{
		if(zer[l]) mn[x]=mp(0,l);
		else mn[x]=mp(inf,l);
		return;
	}
	gm; build(ls,l,mid),build(rs,mid+1,r);
	up(x);
}
void upd(int x,int l,int r,int ql,int qr,int v1,int v2)
{
	if(ql<=l&&r<=qr) return give(x,v1,v2);
	gm; down(x);
	if(ql<=mid) upd(ls,l,mid,ql,qr,v1,v2);
	if(qr>mid) upd(rs,mid+1,r,ql,qr,v1,v2);
	up(x);
}
int ask(int x,int l,int r,int p)
{
	if(l==r) return xt[x];
	gm; down(x);
	if(p<=mid) return ask(ls,l,mid,p);
	else return ask(rs,mid+1,r,p);
}
void upd2(int x,int l,int r,int p)
{
	if(l==r) {mn[x]=mp(inf,l); return;}
	gm; down(x);
	if(p<=mid) upd2(ls,l,mid,p);
	else upd2(rs,mid+1,r,p);
	up(x);
}
int n;
vector<int> E[N];
int dfn[N],dk,sz[N],hsn[N],fa[N],top[N],dep[N];
void dfs(int x,int _fa)
{
	sz[x]=1,fa[x]=_fa,dep[x]=dep[_fa]+1;
	for(solid v:E[x])
	{
		if(v==_fa) continue;
		dfs(v,x); sz[x]+=sz[v];
		if(sz[v]>sz[hsn[x]]) hsn[x]=v;
	}
}
void efs(int x,int _tp)
{
	dfn[x]=++dk,top[x]=_tp;
	// err("E",x,dfn[x]);
	if(hsn[x]) efs(hsn[x],_tp);
	else return;
	for(solid v:E[x])
	{
		if(v==fa[x]||v==hsn[x]) continue;
		efs(v,v);
	}
}
il void lineupd(int x,int y,int v1,int v2)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		upd(rt,1,n,dfn[top[x]],dfn[x],v1,v2);
		x=fa[top[x]];
	}
	if(x==y) return;
	if(dfn[x]>dfn[y]) swap(x,y);
	upd(rt,1,n,dfn[x]+1,dfn[y],v1,v2);
}
set< pii > hve,nwe;
int ea[N],eb[N],cnt;
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
	// freopen("ot.out","w",stdout);
#endif
	in(n);
	for(ri i=1,a,b; i<n; ++i)
	{
		in(a,b);
		E[a].pb(b),E[b].pb(a);
		if(a>b) swap(a,b);
		hve.insert(mp(a,b));
	}
	for(ri i=1; i<n; ++i)
	{
		++cnt,in(ea[cnt],eb[cnt]);
		if(ea[cnt]>eb[cnt]) swap(ea[cnt],eb[cnt]);
		if(hve.count(mp(ea[cnt],eb[cnt]))) hve.erase(mp(ea[cnt],eb[cnt])),--cnt;
	}
	dfs(1,0);
	efs(1,1);
	for(ri i=2; i<=n; ++i)
	{
		int a=i,b=fa[i];
		if(a>b) swap(a,b);
		if(hve.count(mp(a,b))) zer[dfn[i]]=1; //,out(i);
	}
	build(rt,1,n);
	for(ri i=1; i<=cnt; ++i) lineupd(ea[i],eb[i],1,i);
	// for(ri i=1; i<=cnt; ++i) out(i,ea[i],eb[i]);
	int del=0;
	while(1)
	{
		pii tmp=mn[rt];
		if(tmp.fi>1) break;
		if(tmp.fi==0)
		{
			upd2(rt,1,n,tmp.se);
			continue;
		}
		int t=ask(rt,1,n,tmp.se);
		// err("A",tmp.se,ea[t],eb[t]);
		++del;
		lineupd(ea[t],eb[t],-1,t);
	}
	puts(del==cnt?"YES":"NO");
	return 0;
}
#pragma region
}
signed main()
{
	i207M::main();
	return 0;
}
#pragma endregion


Measured memory_bytes: 39936