#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << ", ";
#define endln cerr << "\n";
#define chkpt cerr << "-----\n";

const int MAXN = 1e5 + 5;
int n;
vector<int> adj[MAXN];
int x[MAXN];
int y[MAXN];
int size[MAXN];
int lev[MAXN];
int p[MAXN];
int num[MAXN];
int head[MAXN];
int cnt;

pi st[MAXN << 2];
int lz[MAXN << 2];
void build(int p, int L, int R) {
    if (L == R) {
        st[p].se = L;
        return;
    }
    build(p << 1, L, L + R >> 1);
    build(p << 1 | 1, (L + R >> 1) + 1, R);
    st[p] = min(st[p << 1], st[p << 1 | 1]);
}
void pushdown(int p, int L, int R) {
    if (lz[p]) {
        st[p].fi += lz[p];
        if (L < R) {
            lz[p << 1] += lz[p];
            lz[p << 1 | 1] += lz[p];
        }
        lz[p] = 0;
    }
}
void upd(int p, int l, int r, int L, int R, int val) {
    pushdown(p, L, R);
    if (l > R || r < L) return;
    if (l <= L && r >= R) {
        lz[p] += val;
        pushdown(p, L, R);
        return;
    }
    upd(p << 1, l, r, L, L + R >> 1, val);
    upd(p << 1 | 1, l, r, (L + R >> 1) + 1, R, val);
    st[p] = min(st[p << 1], st[p << 1 | 1]);
}

struct SegTree {
    static const int maxn = 1e5 + 5;
    set<int> st[maxn << 2];
    void add(int p, int l, int r, int L, int R, int val) {
        if (l > R || r < L) return;
        if (l <= L && r >= R) {
            st[p].insert(val);
            return;
        }
        add(p << 1, l, r, L, L + R >> 1, val);
        add(p << 1 | 1, l, r, (L + R >> 1) + 1, R, val);
    }
    void rem(int p, int l, int r, int L, int R, int val) {
        if (l > R || r < L) return;
        if (l <= L && r >= R) {
            st[p].erase(val);
            return;
        }
        rem(p << 1, l, r, L, L + R >> 1, val);
        rem(p << 1 | 1, l, r, (L + R >> 1) + 1, R, val);
    }
    int query(int p, int i, int L, int R) {
        if (i < L || i > R) return -1;
        if (sz(st[p])) return *st[p].begin();
        if (L == R) return -1;
        return max(query(p << 1, i, L, L + R >> 1), query(p << 1 | 1, i, (L + R >> 1) + 1, R));
    }
} seg;

void dfs1(int u, int dad = -1) {
    size[u] = 1;
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (v != dad) {
            p[v] = u, lev[v] = lev[u] + 1;
            dfs1(v, u);
            size[u] += size[v];
        }
    }
}
void dfs2(int u, int h = 0, int dad = -1) {
    num[u] = cnt++, head[u] = h;
    pair<int, int> best = make_pair(-1, -1);
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (v != dad) {
            best = max(best, make_pair(size[v], v));
        }
    }
    if (~best.second) {
        dfs2(best.second, h, u);
    }
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (v != dad && v != best.second) {
            dfs2(v, v, u);
        }
    }
}
void upd(int u, int v, int val, int ix) {
    int hu = head[u], hv = head[v];
    while (hu != hv) {
        if (lev[hu] < lev[hv]) swap(u, v), swap(hu, hv);
        upd(1, num[hu], num[u], 0, n - 1, val);
        if (val == 1) {
            seg.add(1, num[hu], num[u], 0, n - 1, ix);
        }
        else {
            seg.rem(1, num[hu], num[u], 0, n - 1, ix);
        }
        u = p[hu], hu = head[u];
    }
    if (lev[u] > lev[v]) swap(u, v);
    upd(1, num[u] + 1, num[v], 0, n - 1, val);
    if (val == 1) {
        seg.add(1, num[u] + 1, num[v], 0, n - 1, ix);
    }
    else {
        seg.rem(1, num[u] + 1, num[v], 0, n - 1, ix);
    }
}

void solve() {
    cin >> n;
    FOR(i, 0, n - 1) {
        int u, v; cin >> u >> v; u--, v--;
        adj[u].pb(v), adj[v].pb(u);
    }
    dfs1(0), dfs2(0);
    build(1, 0, n - 1);
    FOR(i, 0, n - 1) {
        cin >> x[i] >> y[i], x[i]--, y[i]--;
        upd(x[i], y[i], 1, i);
    }
    upd(1, 0, 0, 0, n - 1, 1000000);
    FOR(i, 0, n - 1) {
        if (st[1].fi != 1) {
            cout << "NO\n";
            return;
        }
        int ix = st[1].se;
        upd(1, ix, ix, 0, n - 1, 1000000);
        int k = seg.query(1, ix, 0, n - 1);
        assert(~k);
        upd(x[k], y[k], -1, k);
    }
    cout << "YES\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 136448