#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int n;
struct Tree {
  set<pair<int, int>> e;
  set<int> l[N];
  int deg[N];
  set<int> c;
  set<pair<int, int>> q, lf;
  inline void add_edge(int u, int v) {
    e.insert({u, v});
    e.insert({v, u});
    l[u].insert(v);
    l[v].insert(u);
    ++deg[u];
    ++deg[v];
  }
  void init() {
    for (int i = 1; i <= n; i++) {
      c.insert(i), q.insert({deg[i], i});
      if (deg[i] == 1) lf.insert({*l[i].begin(), i});
    }
  }
  inline int chk() { return int(c.size() - q.rbegin()->first - 1); }
  int push(int p[], int u, int v, int w) {
    int idx = 0;
    for (auto &i : c)
      if (u != i && v != i && w != i) p[++idx] = i;
    return idx;
  }
  pair<int, int> s[5];
  pair<int, int> get_leaf() {
    s[1] = *lf.begin(), s[2] = *++lf.begin(), s[3] = *lf.rbegin(),
    s[4] = *++lf.rbegin();
    sort(s + 1, s + 5);
    int mx = -1;
    for (int i = 1; i < 5; i++)
      if (deg[s[i].first] > 2) {
        mx = s[i].first;
        break;
      }
    if (mx == -1) return {lf.begin()->second, lf.rbegin()->second};
    int u = -1, v = -1;
    for (int i = 1; i < 5; i++)
      if (s[i].first == mx)
        u = s[i].second;
      else
        v = s[i].second;
    return {u, v};
  }
  void erase(int id) {
    int x = *l[id].begin();
    c.erase(id);
    lf.erase({x, id});
    q.erase({1, id});
    l[id].erase(x);
    l[x].erase(id);
    q.erase({deg[x]--, x});
    q.insert({deg[x], x});
    if (deg[x] == 1) lf.insert({*l[x].begin(), x});
  }
} a, b;
int g[N], h[N], ans[N];
bool chk(int cur) {
  for (int i = 1; i <= cur; i++)
    for (int j = 1; j < i; j++)
      if (a.e.count({g[i], g[j]}) && b.e.count({h[i], h[j]})) return 0;
  return 1;
}
void solve1() {
  int cur = a.push(g, 0, 0, 0);
  b.push(h, 0, 0, 0);
  do
    if (chk(cur)) {
      for (int i = 1; i <= cur; i++) ans[g[i]] = h[i];
      return;
    }
  while (next_permutation(g + 1, g + cur + 1));
}
void solve2(Tree &a, Tree &b) {
  int u = (++a.q.rbegin())->second, v = *a.l[u].begin(), w = *a.l[u].rbegin();
  if (a.deg[w] == 1) swap(v, w);
  int uu = -1, vv = b.lf.begin()->first, ww = b.lf.begin()->second;
  for (auto &i : b.c)
    if (!b.e.count({i, vv}) && !b.e.count({i, ww})) {
      uu = i;
      break;
    }
  ans[u] = uu;
  ans[v] = vv;
  ans[w] = ww;
  int cur = a.push(g, u, v, w);
  b.push(h, uu, vv, ww);
  for (int i = 1; i <= cur; i++) ans[g[i]] = h[i];
}
int tmp[N];
void re() {
  for (int i = 1; i <= n; i++) tmp[ans[i]] = i;
  for (int i = 1; i <= n; i++) ans[i] = tmp[i];
}
void solve() {
  if (a.c.size() < 4 || !a.chk() || !b.chk()) {
    puts("No");
    exit(0);
  }
  if (a.c.size() < 6) return solve1();
  if (a.chk() == 1) return solve2(a, b);
  if (b.chk() == 1) {
    solve2(b, a);
    return re();
  }
  pair<int, int> aa = a.get_leaf(), cc = b.get_leaf(),
                 bb = {*a.l[aa.first].begin(), *a.l[aa.second].begin()},
                 dd = {*b.l[cc.first].begin(), *b.l[cc.second].begin()};
  a.erase(aa.first);
  a.erase(aa.second);
  b.erase(cc.first);
  b.erase(cc.second);
  solve();
  if (ans[bb.first] != dd.first && ans[bb.second] != dd.second)
    ans[aa.first] = cc.first, ans[aa.second] = cc.second;
  else
    ans[aa.first] = cc.second, ans[aa.second] = cc.first;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    a.add_edge(t1, t2);
  }
  for (int i = 1; i < n; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    b.add_edge(t1 - n, t2 - n);
  }
  a.init();
  b.init();
  solve();
  cout << "Yes" << endl;
  for (int i = 1; i <= n; i++) cout << ans[i] + n << ' ';
  return 0;
}
