#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<unordered_set>
#define N 200001
#define ls(_o) (_o<<1)
#define rs(_o) ((_o<<1)|1)
using namespace std;
namespace ywy{
	inline int get(){
		int n=0;char c;while((c=getchar())||23333){
			if(c>='0'&&c<='9')break;if(c=='-')goto s;
		}n=c-'0';while((c=getchar())||23333){
			if(c>='0'&&c<='9')n=n*10+c-'0';else return(n);
		}s:while((c=getchar())||23333){
			if(c>='0'&&c<='9')n=n*10-c+'0';else return(n);
		}
	}
	typedef struct _b{
		int dest;int nxt;
	}bian;bian memchi[400001];int gn=1,heads[N],dfn[N],top[N],deep[N],fa[N],gdfn=1,size[N],zhongson[N];
	inline void add(int s,int t){
		memchi[gn].dest=t;memchi[gn].nxt=heads[s];heads[s]=gn;gn++;
	}unordered_set<int> st[800001];int minn[800001],minpos[800001],adds[800001];
	inline void down(int tree){
		if(!adds[tree])return;adds[ls(tree)]+=adds[tree];adds[rs(tree)]+=adds[tree];
		minn[ls(tree)]+=adds[tree];minn[rs(tree)]+=adds[tree];adds[tree]=0;
	}
	inline void up(int tree){
		minn[tree]=min(minn[ls(tree)],minn[rs(tree)]);
		if(minn[ls(tree)]==minn[tree])minpos[tree]=minpos[ls(tree)];else minpos[tree]=minpos[rs(tree)];
	}
	void dfs(int pt,int baba){
		size[pt]=1;int mx=0,best=0;top[pt]=pt;for(register int i=heads[pt];i;i=memchi[i].nxt){
			if(memchi[i].dest==baba)continue;deep[memchi[i].dest]=deep[pt]+1;fa[memchi[i].dest]=pt;
			dfs(memchi[i].dest,pt);size[pt]+=size[memchi[i].dest];
			if(size[memchi[i].dest]>mx)mx=size[memchi[i].dest],best=memchi[i].dest;
		}zhongson[pt]=best;
	}
	void efs(int pt,int baba){
		dfn[pt]=gdfn;gdfn++;if(zhongson[pt])top[zhongson[pt]]=top[pt],efs(zhongson[pt],pt);
		for(register int i=heads[pt];i;i=memchi[i].nxt){
			if(memchi[i].dest==baba||memchi[i].dest==zhongson[pt])continue;efs(memchi[i].dest,pt);
		}
	}
	void build(int l,int r,int tree){
		if(l==r){
			if(l==1)minn[tree]=12345678;minpos[tree]=l;return;
		}int mid=(l+r)>>1;build(l,mid,ls(tree));build(mid+1,r,rs(tree));up(tree);
	}
	void fg(int rl,int rr,int l,int r,int tree,int id){
		if(rl>rr)return;if(rl==l&&rr==r){
			st[tree].insert(id);adds[tree]++;minn[tree]++;return;
		}int mid=(l+r)>>1;down(tree);if(rl>mid)fg(rl,rr,mid+1,r,rs(tree),id);else{
			if(rr<=mid)fg(rl,rr,l,mid,ls(tree),id);else{
				fg(rl,mid,l,mid,ls(tree),id);fg(mid+1,rr,mid+1,r,rs(tree),id);
			}
		}up(tree);
	}
	void che(int rl,int rr,int l,int r,int tree,int id){
		if(rl>rr)return;if(rl==l&&rr==r){
			st[tree].erase(id);adds[tree]--;minn[tree]--;return;
		}int mid=(l+r)>>1;down(tree);if(rl>mid)che(rl,rr,mid+1,r,rs(tree),id);else{
			if(rr<=mid)che(rl,rr,l,mid,ls(tree),id);else{
				che(rl,mid,l,mid,ls(tree),id);che(mid+1,rr,mid+1,r,rs(tree),id);
			}
		}up(tree);
	}int ss[200001],ts[200001];int zx=0;
	void setpt(int l,int r,int tree,int pt){
		if(!st[tree].empty())zx=*st[tree].begin();if(l==r){
			minn[tree]=12345678;return;
		}int mid=(l+r)>>1;down(tree);if(pt<=mid)setpt(l,mid,ls(tree),pt);else setpt(mid+1,r,rs(tree),pt);up(tree);
	}
	void ywymain(){
		int n=get();for(register int i=1;i<n;i++){
			int s=get(),t=get();add(s,t);add(t,s);
		}dfs(1,0);efs(1,0);build(1,n,1);for(register int i=1;i<n;i++){
			ss[i]=get(),ts[i]=get();int s=ss[i],t=ts[i];while(top[s]!=top[t]){
				if(deep[top[s]]>deep[top[t]])swap(s,t);fg(dfn[top[t]],dfn[t],1,n,1,i);t=fa[top[t]];
			}if(deep[s]>deep[t])swap(s,t);fg(dfn[s]+1,dfn[t],1,n,1,i);
		}for(register int i=1;i<n;i++){
			if(minn[1]!=1){
				printf("NO\n");return;
			}int me=minpos[1];zx=0;setpt(1,n,1,me);if(!zx){
				printf("NO\n");return;
			}int s=ss[zx],t=ts[zx];while(top[s]!=top[t]){
				if(deep[top[s]]>deep[top[t]])swap(s,t);che(dfn[top[t]],dfn[t],1,n,1,zx);t=fa[top[t]];
			}if(deep[s]>deep[t])swap(s,t);che(dfn[s]+1,dfn[t],1,n,1,zx);
		}printf("YES\n");
	}
}
int main(){
	ywy::ywymain();return(0);
}

Measured memory_bytes: 171864