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

#define int long long
#define inf 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

class Dinic {
public:
  vector<vector<pair<int, int>>> v;
  vector<int> e;

  vector<int> k;
  vector<int> j;

  void init(int n) {
    v = vector<vector<pair<int, int>>>(n);
    e = vector<int>();
    k = vector<int>(n);
    j = vector<int>(n);
  }
  void add_edge(int a, int b, int atob, int btoa = 0) {
    v[a].push_back(make_pair(b, e.size()));
    e.push_back(atob);
    v[b].push_back(make_pair(a, e.size()));
    e.push_back(btoa);
  }
  void dyk(int s) {
    for(auto& i : k) {
      i = inf;
    }
    queue<pair<int, int>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()) {
      int w = pq.front().first;
      int b = pq.front().second;
      pq.pop();
      if(k[b] > w) {
        k[b] = w;
        for(auto i : v[b]) {
          if(e[i.second] > 0) {
            pq.push(make_pair(w + 1, i.first));
          }
        }
      }
    }
  }
  int dfs(int s, int t, int p, int c) {
    if(p == t) {
      return c;
    }
    int all = 0;
    while(c > all && j[p] < v[p].size()) {
      if(k[v[p][j[p]].first] == k[p] + 1) {
        int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second]));
        e[v[p][j[p]].second] -= r;
        e[v[p][j[p]].second ^ 1] += r;
        if(r < c - all) {
          j[p]++;
        }
        all += r;
      }
      else {
        j[p]++;
      }
    }
    return all;
  }
  int solve(int s, int t) {
    int all = 0;
    while(1) {
      dyk(s);
      for(auto& i : j) {
        i = 0;
      }
      int r = dfs(s, t, s, inf);
      if(r == 0) {
        return all;
      }
      all += r;
    }
  }
};

pair<int, pair<int, int>> operator+(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
  return make_pair(a.first + b.first, make_pair(a.second.first + b.second.first, a.second.second + b.second.second));
}

class Seg {
public:
  vector<pair<int, pair<int, int>>> d, a;
  int n;

  void init(int nw) {
    n = 1;
    while(n <= nw) {
      n *= 2;
    }
    d.resize(n * 2);
    a.resize(n * 2);
    rep(i, nw) {
      d[n - 1 + i] = make_pair(0LL, make_pair(0LL, i));
      a[n - 1 + i] = make_pair(0LL, make_pair(0LL, 0LL));
    }
    mfor(i, nw, n) {
      d[n - 1 + i] = make_pair(inf, make_pair(0LL, 0LL));
      a[n - 1 + i] = make_pair(0LL, make_pair(0LL, 0LL));
    }
    rrep(i, n - 1) {
      d[i] = min(d[i * 2 + 1], d[i * 2 + 2]);
      a[i] = make_pair(0LL, make_pair(0LL, 0LL));
    }
  }
  void add_(int b, int e, int k, int x, int p, int nb, int ne) {
    if(b <= nb && ne <= e) {
      a[p] = a[p] + make_pair(k, make_pair(x, 0));
    }
    else if(ne <= b || e <= nb) {}
    else {
      a[p * 2 + 1] = a[p * 2 + 1] + a[p];
      a[p * 2 + 2] = a[p * 2 + 2] + a[p];
      int m = (nb + ne) / 2;
      add_(b, e, k, x, p * 2 + 1, nb, m);
      add_(b, e, k, x, p * 2 + 2, m, ne);
      d[p] = min(a[p * 2 + 1] + d[p * 2 + 1], a[p * 2 + 2] + d[p * 2 + 2]);
      a[p] = make_pair(0, make_pair(0, 0));
    }
  }
  void add(int b, int e, int k, int x) {
    add_(b, e, k, x, 0, 0, n);
  }
  pair<int, pair<int, int>> solve() {
    return a[0] + d[0];
  }
};

Seg se;

vector<int> v[114514];

int son[114514];

int dfs1(int p, int o) {
  son[p] = 1;
  for(auto i : v[p]) {
    if(i != o) {
      son[p] += dfs1(i, p);
    }
  }
  return son[p];
}

int iti[114514];
int top[114514];
int par[114514];

int nk = 0;

void dfs2(int p, int o, int b) {
  iti[p] = nk++;
  top[p] = b;
  pair<int, int> ma = make_pair(0, -1);
  for(auto i : v[p]) {
    if(i != o) {
      ma = max(ma, make_pair(son[i], i));
    }
  }
  if(ma.second >= 0) {
    dfs2(ma.second, p, b);
  }
  for(auto i : v[p]) {
    if(i != o && i != ma.second) {
      par[i] = p;
      dfs2(i, p, i);
    }
  }
}

void add(int a, int b, int k, int x) {
  while(top[a] != top[b]) {
    if(iti[a] > iti[b]) {
      se.add(iti[top[a]], iti[a] + 1, k, x);
      a = par[top[a]];
    }
    else {
      se.add(iti[top[b]], iti[b] + 1, k, x);
      b = par[top[b]];
    }
  }
  se.add(min(iti[a], iti[b]) + 1, max(iti[a], iti[b]) + 1, k, x);
}

pair<int, int> qu[114514];

signed main() {
  int n;
  cin >> n;
  se.init(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs1(0, -1);
  dfs2(0, -1, 0);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    add(a, b, 1, i);
    qu[i] = make_pair(a, b);
  }
  se.add(0, 1, inf, 0);
  rep(i, n - 1) {
    auto w = se.solve();
    if(w.first == 1) {
      int q = w.second.first;
      int b = w.second.second;
      add(qu[q].first, qu[q].second, -1, -q);
      se.add(b, b + 1, inf, 0);
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 31744