#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int N;
struct gt {
  set<int> mp[100005], lf2, tof[100005], nodes;
  set<pair<int, int> > sp;
  int d[100005];
  void rd() {
    for (int(i) = 0; (i) < (int)(n - 1); (i)++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u > n) {
        u -= n;
        v -= n;
      }
      d[u]++;
      d[v]++;
      mp[u].insert(v);
      mp[v].insert(u);
    }
    for (int(i) = 1; (i) <= (int)(n); (i)++) sp.insert({d[i], i});
    for (int(i) = 1; (i) <= (int)(n); (i)++) {
      if (d[i] == 1) {
        for (int gg : mp[i]) {
          lf2.insert(gg);
          tof[gg].insert(i);
        }
      }
      nodes.insert(i);
    }
  }
  bool isStar() { return sp.rbegin()->first == N - 1; }
  bool is1Star() { return sp.rbegin()->first == N - 2; }
  void rm(int x) {
    nodes.erase(x);
    assert(d[x] == 1);
    int F = *mp[x].begin();
    tof[F].erase(x);
    if (tof[F].empty()) {
      lf2.erase(F);
    }
    sp.erase({d[x], 1});
    sp.erase({d[F], F});
    d[F]--;
    sp.insert({d[F], F});
    d[x] = 0;
    mp[F].erase(x);
    mp[x].erase(F);
    if (d[F] == 1) {
      assert(mp[F].size() == 1);
      int zz = *mp[F].begin();
      tof[zz].insert(F);
      lf2.insert(zz);
    }
  }
  void getPair(int &tu, int &u, int &tv, int &v) {
    int C = sp.rbegin()->second;
    if (d[C] == N - 3) {
      assert(lf2.count(C));
      tu = C;
      u = *tof[C].begin();
      for (int z : lf2)
        if (z != C) {
          tv = z;
          v = *tof[tv].begin();
        }
      return;
    }
    tu = *lf2.begin();
    u = *tof[tu].begin();
    tv = *lf2.rbegin();
    v = *tof[tv].begin();
  }
} T[2];
int ans[100005];
void ppt() {
  for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d ", ans[i] + n);
  exit(0);
}
void abri() {
  vector<int> A, B, C;
  for (int nd : T[0].nodes) A.push_back(nd);
  for (int nd : T[1].nodes) B.push_back(nd);
  C.resize(N);
  for (int(i) = 0; (i) < (int)(N); (i)++) C[i] = i;
  do {
    map<int, int> tmp;
    for (int(i) = 0; (i) < (int)(N); (i)++) tmp[A[i]] = B[C[i]];
    bool ok = 1;
    for (int x : A) {
      for (int y : T[0].mp[x]) {
        int X = tmp[x], Y = tmp[y];
        if (T[1].mp[X].count(Y)) {
          ok = 0;
          break;
        }
      }
      if (ok == 0) break;
    }
    if (ok) {
      for (int(i) = 0; (i) < (int)(N); (i)++) ans[A[i]] = B[C[i]];
      break;
    }
  } while (next_permutation(C.begin(), C.end()));
}
void mt(int x, int y, bool rev) {
  if (rev)
    ans[x] = y;
  else
    ans[y] = x;
}
void cal() {
  if (N <= 5) {
    abri();
    return;
  }
  if (T[0].is1Star() || T[1].is1Star()) {
    bool first = T[0].is1Star();
    if (!first) swap(T[0], T[1]);
    int w = T[0].sp.rbegin()->second;
    int u, v;
    for (int zz : T[0].lf2)
      if (zz != w) {
        u = zz;
        for (int zzz : T[0].mp[u])
          if (zzz != w) {
            v = zzz;
            break;
          }
        break;
      }
    int v1 = *T[1].lf2.begin();
    int w1, u1;
    for (int z : T[1].mp[v1])
      if (T[1].d[z] == 1) {
        w1 = z;
        break;
      }
    for (int nd : T[1].nodes)
      if (T[1].mp[nd].count(w1) == 0 && T[1].mp[nd].count(v1) == 0) {
        u1 = nd;
        break;
      }
    mt(w, w1, first);
    mt(u, u1, first);
    mt(v, v1, first);
    vector<int> A, B;
    for (int nd : T[0].nodes)
      if (nd != w && nd != u && nd != v) {
        A.push_back(nd);
      }
    for (int nd : T[1].nodes)
      if (nd != w1 && nd != u1 && nd != v1) {
        B.push_back(nd);
      }
    for (int(i) = 0; (i) < (int)(A.size()); (i)++) mt(A[i], B[i], first);
    if (!first) swap(T[0], T[1]);
    return;
  }
  int tu, u, tv, v;
  T[0].getPair(tu, u, tv, v);
  int tu1, u1, tv1, v1;
  T[1].getPair(tu1, u1, tv1, v1);
  T[0].rm(u);
  T[0].rm(v);
  T[1].rm(u1);
  T[1].rm(v1);
  N -= 2;
  cal();
  if (ans[tu] != tu1 && ans[tv] != tv1) {
    mt(u, u1, 1);
    mt(v, v1, 1);
  } else {
    mt(u, v1, 1);
    mt(v, u1, 1);
  }
}
void fmain(int ID) {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(2); (i)++) T[i].rd();
  N = n;
  for (int(i) = 0; (i) < (int)(2); (i)++)
    if (T[i].isStar()) etp();
  puts("Yes");
  cal();
  ppt();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
