#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define SZ 131072
using namespace std;
int n, UF[101000], pp[101000], Num[101000], C[101000], Dep[101000], par[101000][20], Ed[101000], cnt;
vector<int>E[101000], G[101000], T[101000];
int IT[SZ+SZ];
set<int>Set[SZ+SZ];
struct Edge{
    int a, b;
}ord[101000], Q[101000];
void DFS(int a, int p){
    int i, x;
    C[a] = 1;
    par[a][0]=p;
    for(i=0;i<18;i++)par[a][i+1] = par[par[a][i]][i];
    for(i=0;i<E[a].size();i++){
        x = E[a][i];
        if(x==p)continue;
        Dep[x] = Dep[a] + 1;
        DFS(x, a);
        C[a] += C[x];
    }
}
void HLD(int a, int p, int ppp){
    pp[a] = ppp;
    Num[a] = ++cnt;
    int i, x, M = -1, pv = -1;
    for(i=0;i<E[a].size();i++){
        x=E[a][i];
        if(x==p)continue;
        if(M < C[x])M=C[x], pv = x;
    }
    if(M==-1)return;
    HLD(pv, a, ppp);
    for(i=0;i<E[a].size();i++){
        x=E[a][i];
        if(x==p||x==pv)continue;
        HLD(x, a, x);
    }
    Ed[a] = cnt;
}
int LCA(int a, int b){
    if(Dep[a] < Dep[b])return LCA(b,a);
    int d = Dep[a]-Dep[b], i = 0;
    while(d){
        if(d&1)a = par[a][i];
        i++;d>>=1;
    }
    for(i=16;i>=0;i--){
        if(par[a][i]!=par[b][i])a=par[a][i],b=par[b][i];
    }
    if(a!=b)a=par[a][0];
    return a;
}
void Ins(int nd, int b, int e, int s, int l, int x){
    if(b==s && e==l){
        if(x > 0){
            Set[nd].insert(x),IT[nd]++;
        }
        else{
            Set[nd].erase(-x),IT[nd]--;
        }
        return;
    }
    int m = (b+e)>>1;
    if(s<=m)Ins(nd+nd, b, m, s, min(m,l),x);
    if(l>m)Ins(nd+nd+1, m+1, e, max(s,m+1), l,x);
    IT[nd] = min(IT[nd+nd], IT[nd+nd+1]) + Set[nd].size();
}
void Del(int nd, int b, int e, int x){
    if(b==e){
        IT[nd] = 1e6;
        return;
    }
    int m = (b+e)>>1;
    if(x<=m)Del(nd+nd, b, m, x);
    if(x>m)Del(nd+nd+1, m+1, e, x);
    IT[nd] = min(IT[nd+nd], IT[nd+nd+1]) + Set[nd].size();
}
void Add(int a, int p, int y){
    while(1){
        if(a==p)return;
        int t = pp[a];
        if(Dep[t] <= Dep[p]){
            Ins(1, 2, n, Num[p]+1, Num[a], y);
            break;
        }
        else{
            Ins(1, 2, n, Num[t], Num[a], y);
        }
        a = par[t][0];
    }
}
int nn, xx;
void Find(int nd, int b, int e){
    int m = (b+e)>>1, sz = Set[nd].size();
    if(sz){
        nn = *Set[nd].begin();
    }
    if(b==e){
        xx = b;
        return;
    }
//    printf("%d %d %d %d\n",IT[nd],IT[nd+nd],IT[nd+nd+1],sz);
    if(IT[nd] == IT[nd+nd] + sz)Find(nd+nd, b, m);
    else Find(nd+nd+1, m+1, e);
}
int Find(int a){
    if(a==UF[a])return a;
    return Find(UF[a]);
}
int Merge(int a, int b){
    int i, j, s = 0;
    a = Find(a), b = Find(b);
    if(G[a].size() < G[b].size())swap(a,b);
    for(i=0;i<G[b].size();i++){
        int x = G[b][i];
        for(j=0;j<T[x].size();j++){
            if(Find(T[x][j]) == a)s++;
        }
        G[a].push_back(x);
    }
    UF[b] = a;
    return s;
}
int main(){
    int i, a, b;
    scanf("%d",&n);
    for(i=1;i<n;i++){
        scanf("%d%d",&a,&b);
        E[a].push_back(b);
        E[b].push_back(a);
    }
    DFS(1,0);
    HLD(1,0,1);
    for(i=1;i<=n;i++)UF[i] = i, G[i].push_back(i);
    for(i=1;i<n;i++){
        scanf("%d%d",&a,&b);
        Q[i].a = a, Q[i].b = b;
        T[a].push_back(b);
        T[b].push_back(a);
        int l = LCA(a,b);
        Add(a,l,i);
        Add(b,l,i);
    }
    for(i=1;i<n;i++){
        if(IT[1] != 1){
            printf("NO\n");
            return 0;
        }
        Find(1, 2, n);
//        printf("%d\n",xx);
        Del(1, 2, n, xx);
        a = Q[nn].a, b = Q[nn].b;
    //    printf("%d %d\n",a,b);
        ord[i] = Q[nn];
        int l = LCA(a, b);
        Add(a,l,-nn);
        Add(b,l,-nn);
    }
    for(i=1;i<n;i++){
        if(Merge(ord[i].a,ord[i].b)!=1){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}

Measured memory_bytes: 125176