#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxv = 1e5+5;
int uf[maxv];
set<int> G[maxv];
map<PII,int> E;

int find(const int x)
{
    if (x != uf[x])
        uf[x] = find(uf[x]);    /* pass compression */
    return uf[x];
}

void unin(const int x, const int y)
{
    const int a = find(x), b = find(y);
    uf[b] = a;
}

PII makee(const int u, const int v)
{ return u > v ? PII(v,u) : PII(u,v); }

PII connect(const int u, const int v)
{ G[u].insert(v); G[v].insert(u); return makee(u,v); }

void disconnect(const int u, const int v)
{ G[u].erase(v); G[v].erase(u); }

int main()
{
    int N;
    while (cin >> N) {
        FOR(i,1,N+1)
            uf[i] = i;
        E.clear();
        FOR(_,0,2*(N-1)) {
            int u,v; cin >> u >> v;
            const PII e = connect(u,v);
            E[e]++;
        }
        queue<PII> Q;
        FOR_ALL(e,E) if (e->second >= 2)
            Q.push(e->first);
        while (Q.size()) {
            const PII e = Q.front(); Q.pop();
            const int x = find(e.first);
            const int y = find(e.second);
            unin(x,y);
            const int u = find(x);
            const int v = u == x ? y : x;
            const set<int> gv = G[v];
            FOR_ALL(i,gv) {
                const int w = find(*i);
                if (w != u) {
                    const PII ee = connect(u,w);
                    E[ee]++;
                    if (E[ee] >= 2) {
                        Q.push(ee);
                    }
                }
                disconnect(v,w);
            }
        }
        set<int> S;
        FOR(i,1,N+1)
            S.insert(find(i));
        const string ans = S.size() == 1 ? "YES" : "NO";
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 146048