#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N],mol[N];
map <pii,int> yal;
queue <pii> q;
ll par[N];
void add_edge(ll u,ll v){
    yal[{u,v}]++;
    yal[{v,u}]++;
    if (yal[{u,v}]>1 && u!=v){
        q.push({u,v});
    }
    return ;
}
void mrg(ll u,ll v){
    if (mol[u].size()>mol[v].size()) swap(u,v);
    for (auto t : g[u]){
        add_edge(v,par[t]);
        g[v].pb(par[t]);
    }
    g[u].clear();
    for (auto t : mol[u]){
        par[t]=v;
        mol[v].pb(t);
    }
    mol[u].clear();
    return ;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<N;i++) par[i]=i,mol[i].pb(i);
    for (int i=1;i<2*n-1;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
        add_edge(u,v);
    }
    while(q.size()){
        pii a=q.front();
        q.pop();
       // cout << a.F << " " << a.S << endl;
        mrg(a.F,a.S);
    }
    ll y=par[1];
    for (int i=2;i<=n;i++){
        if (par[i]!=y) kill("NO");
    }
    kill("YES");

}
