#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int fa[maxn],son[maxn],size[maxn],dep[maxn],l[maxn],an[maxn],dfn;

int Is[maxn];

int U[maxn],V[maxn];

int val[maxn*30],nxt[maxn*30],cnt;

vector<int> G[maxn];

void dfs1(int u,int f){
	size[u]=1;
	fa[u]=f;
	dep[u]=dep[f]+1;
	for(auto v:G[u])if(v!=f)dfs1(v,u),size[u]+=size[v];
	if(size[u]>size[son[fa[u]]])son[fa[u]]=u;
}

void dfs2(int u,int anc){
	an[u]=anc;
	l[u]=++dfn;
	if(son[u])dfs2(son[u],anc);
	for(auto v:G[u])if(v!=fa[u]&&v!=son[u])dfs2(v,v);
}

int c[maxn];

void add(int x,int y){
	for(;x<=n;x+=x&-x)c[x]^=y;
}
int query(int x){
	int ans=0;
	for(;x;x-=x&-x)ans^=c[x];
	return ans;
}

struct Node{
	int l,r,mn,pos,bj;
}T[maxn<<2];

void pushdown(int i){
	int x=T[i].bj;T[i].bj=0;
	T[i<<1].mn+=x;T[i<<1].bj+=x;
	T[i<<1|1].mn+=x;T[i<<1|1].bj+=x;
}

void pushup(int i){
	if(T[i<<1].mn<T[i<<1|1].mn)T[i].mn=T[i<<1].mn,T[i].pos=T[i<<1].pos;else T[i].mn=T[i<<1|1].mn,T[i].pos=T[i<<1|1].pos;
}

void build(int i,int l,int r){
	T[i].l=l;T[i].r=r;
	if(T[i].l==T[i].r){
		T[i].pos=l;
		return;
	}
	int M=l+r>>1;
	build(i<<1,l,M);build(i<<1|1,M+1,r);
	pushup(i);
}

void add(int i,int l,int r,int val){
	if(l<=T[i].l&&T[i].r<=r){
		T[i].mn+=val;T[i].bj+=val;
		return;
	}
	pushdown(i);
	int M=T[i].l+T[i].r>>1;
	if(l<=M)add(i<<1,l,r,val);if(r>M)add(i<<1|1,l,r,val);
	pushup(i);
}

void add2(int u,int v,int id,int val){
	while(an[u]!=an[v]){
		if(dep[an[u]]>dep[an[v]])swap(u,v);
		add(1,l[an[v]],l[v],val);
		add(l[an[v]],id);add(l[v]+1,id);
		v=fa[an[v]];
	}
	if(l[u]>l[v])swap(u,v);
	if(l[u]<l[v]){
		add(1,l[u]+1,l[v],val);
		add(l[u]+1,id);add(l[v]+1,id);
	}
}

void Work(){
	build(1,2,n);
	REP(i,2,n){
		read(U[i],V[i]);
		add2(U[i],V[i],i,1);
	}
	REP(i,2,n){
		if(T[1].mn>1){
			puts("NO");
			return;
		}
		int id=query(T[1].pos);
		add(1,T[1].pos,T[1].pos,0x3f3f3f3f);
		add2(U[id],V[id],id,-1);
	}
	puts("YES");
}

void Init(){
	read(n);
	REP(i,2,n){
		int u,v;
		read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
	dfs1(1,0);
	dfs2(1,1);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 25984