#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10;
int n,p,TIME;
int head[N],dep[N],num[N],son[N],dfn[N],low[N],nw[N],top[N],fa[N],U[N],V[N];
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N<<1];
void ADD(int a,int b) {
  edge[++p]=Edge(b,head[a]); head[a]=p;
  edge[++p]=Edge(a,head[b]); head[b]=p;
}
void DFS(int u,int f) {
  num[u]=1; fa[u]=f;
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    if(v!=f) {
      dep[v]=dep[u]+1; DFS(v,u);
      num[u]+=num[v];
      if(num[v]>num[son[u]]) son[u]=v;
    }
  }
}
void SFD(int u,int topv) {
  nw[dfn[u]=++TIME]=u; top[u]=topv;
  if(son[u]) SFD(son[u],topv);
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    if(!dfn[v]) SFD(v,v);
  }
  low[u]=TIME;
}
int MINV[N<<2],lazy[N<<2],pos[N<<2];
set<int> S[N<<2];
#define L o<<1
#define R o<<1|1
void Down(int o,int v) {
  MINV[o]+=v; lazy[o]+=v;
}
void Pushup(int o) {
  MINV[o]=min(MINV[L],MINV[R]);
  if(MINV[L]<MINV[R]) pos[o]=pos[L];
  else pos[o]=pos[R];
}
void Pushdown(int o) {
  if(lazy[o]) {
    Down(L,lazy[o]); Down(R,lazy[o]);
    lazy[o]=0;
  }
}
void Build(int l,int r,int o) {
  pos[o]=l;
  if(l==r) {
    if(l==1) MINV[o]=2e9;
    return;
  }
  int mid=l+r>>1;
  Build(l,mid,L); Build(mid+1,r,R);
}
void Modify(int l,int r,int o,int ql,int qr,int v,int id) {
  if(ql<=l&&r<=qr) {
    if(v>0) S[o].insert(id);
    else S[o].erase(S[o].find(id));
    return Down(o,v);
  }
  Pushdown(o);
  int mid=l+r>>1;
  if(ql<=mid) Modify(l,mid,L,ql,qr,v,id);
  if(qr>mid) Modify(mid+1,r,R,ql,qr,v,id);
  Pushup(o);
}
int Get(int l,int r,int o,int pos) {
  if(S[o].size()) return *S[o].begin();
  Pushdown(o);
  int mid=l+r>>1,t;
  if(pos<=mid) t=Get(l,mid,L,pos);
  else t=Get(mid+1,r,R,pos);
  Pushup(o);
  return t;
}
void Inf(int l,int r,int o,int pos) {
  if(l==r) {
    MINV[o]=2e9;
    return;
  }
  Pushdown(o);
  int mid=l+r>>1;
  if(pos<=mid) Inf(l,mid,L,pos);
  else Inf(mid+1,r,R,pos);
  Pushup(o);
}
void Change(int u,int v,int val,int id) {
  while(top[u]!=top[v]) {
    if(dep[top[u]]<dep[top[v]]) swap(u,v);
    Modify(1,n,1,dfn[top[u]],dfn[u],val,id);
    u=fa[top[u]];
  }
  if(u==v) return;
  if(dep[u]>dep[v]) swap(u,v);
  Modify(1,n,1,dfn[u]+1,dfn[v],val,id);
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
//  freopen("data.in","r",stdin);
//  freopen("M.out","w",stdout);
  read(n);
  for(int i=1;i<n;++i) {
    int u,v; read(u,v);
    ADD(u,v);
  }
  DFS(1,0); SFD(1,1);
  Build(1,n,1);
  for(int i=1;i<n;++i) {
    read(U[i],V[i]);
    Change(U[i],V[i],1,i);
  }
  for(int i=1;i<n;++i) {
    //printf("#%d :%d\n",i,MINV[1]);
    if(MINV[1]!=1) return puts("NO"),0;
    int id=Get(1,n,1,pos[1]),gg=pos[1];
    Change(U[id],V[id],-1,id); Inf(1,n,1,gg);
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 133120