#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=998244353;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
}
//using namespace Modulo;
namespace Miracle{
const int N=1e5+5;
const int inf=0x3f3f3f3f;
int n;
struct node{
    int nxt,to;
}e[2*N];
int hd[N],cnt;
void lin(int x,int y){
    e[++cnt].nxt=hd[x];
    e[cnt].to=y;
    hd[x]=cnt;
}
int dfn[N],df;
int son[N],sz[N],top[N],fa[N],dep[N];
bool del[N];
void dfs(int x){
    sz[x]=1;dep[x]=dep[fa[x]]+1;
    for(reg i=hd[x];i;i=e[i].nxt){
        int y=e[i].to;
        if(y==fa[x]) continue;
        fa[y]=x;
        dfs(y);
        sz[x]+=sz[y];
        if(sz[y]>sz[son[x]]) son[x]=y;
    }
}
void dfs2(int x){
    dfn[x]=++df;
    if(!top[x]) top[x]=x;
    if(son[x]) top[son[x]]=top[x],dfs2(son[x]);
    for(reg i=hd[x];i;i=e[i].nxt){
        int y=e[i].to;
        if(y==son[x]||y==fa[x]) continue;
        dfs2(y);
    }
}
int b[N][2];
struct tr{
    int mi,id;
    int tag;
    vector<int>mem;
}t[4*N];
#define mid ((l+r)>>1)
#define ls (x<<1)
#define rs (x<<1|1)
void pushup(int x){
    t[x].mi=min(t[ls].mi,t[rs].mi);
    if(t[ls].mi==t[x].mi) t[x].id=t[ls].id;
    else t[x].id=t[rs].id;
}
void add(int x,int c){
    t[x].mi+=c;t[x].tag+=c;
}
void pushdown(int x){
    if(!t[x].tag) return;
    add(ls,t[x].tag);add(rs,t[x].tag);
    t[x].tag=0;
}
void build(int x,int l,int r){
    if(l==r){
        if(l==1) t[x].mi=inf,t[x].id=l;
        else t[x].mi=0;t[x].id=l;
        return;
    }
    build(ls,l,mid);
    build(rs,mid+1,r);
    pushup(x);
}
void push(int x,int l,int r,int L,int R,int id){
    if(L<=l&&r<=R){
        t[x].mem.pb(id);return ;
    }
    if(L<=mid) push(ls,l,mid,L,R,id);
    if(mid<R) push(rs,mid+1,r,L,R,id);
}
int cur;
void fin(int x,int l,int r,int p){
    while(!t[x].mem.empty()&&del[t[x].mem.back()]) t[x].mem.pop_back();
    if(t[x].mem.size()){
        cur=t[x].mem.back();
    }
    if(l==r){
        t[x].mi=inf;return;
    }
    pushdown(x);
    if(p<=mid) fin(ls,l,mid,p);
    else fin(rs,mid+1,r,p);
    pushup(x);
}
void upda(int x,int l,int r,int L,int R,int c){
    if(L<=l&&r<=R){
        add(x,c);return;
    }
    pushdown(x);
    if(L<=mid) upda(ls,l,mid,L,R,c);
    if(mid<R) upda(rs,mid+1,r,L,R,c);
    pushup(x);
}
void chan(int x,int y,int c){
    while(top[x]!=top[y]){
        if(dep[top[x]]<dep[top[y]]) swap(x,y);
        upda(1,1,n,dfn[top[x]],dfn[x],c);
        x=fa[top[x]];
    }
    if(dep[x]<dep[y]) swap(x,y);
    if(dfn[y]+1<=dfn[x]) upda(1,1,n,dfn[y]+1,dfn[x],c);
}
void put(int x,int y,int id){
    while(top[x]!=top[y]){
        if(dep[top[x]]<dep[top[y]]) swap(x,y);
        push(1,1,n,dfn[top[x]],dfn[x],id);
        x=fa[top[x]];
    }
    if(dep[x]<dep[y]) swap(x,y);
    if(dfn[y]+1<=dfn[x]) push(1,1,n,dfn[y]+1,dfn[x],id);
}
int main(){
    rd(n);
    int x,y;
    for(reg i=1;i<n;++i){
        rd(x);rd(y);lin(x,y);lin(y,x);
    }
    dfs(1);
    dfs2(1);
    build(1,1,n);
    for(reg i=1;i<n;++i){
        rd(b[i][0]);rd(b[i][1]);
        chan(b[i][0],b[i][1],1);
        put(b[i][0],b[i][1],i);
    }
    for(reg i=1;i<n;++i){
        if(t[1].mi!=1){
            puts("NO");return 0;
        }
        int id=t[1].id;
        cur=0;
        fin(1,1,n,id);
        del[cur]=1;
        chan(b[cur][0],b[cur][1],-1);
    }
    puts("YES");
    return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

Measured memory_bytes: 37956