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

const int maxn = 3e5 + 10;

int n, u, v, a[maxn];
int fa[maxn];

vector<int> g[maxn];
bool cmp (int x, int y) {return a[x] < a[y];}
int lst, now, ed; long long ans;

void NO () {
    puts ({"NO"});
    exit(0);
}

int dfn[maxn], out[maxn], dfs_clock;
int pre, suf;
void dfs (int u, int dep)
{
    dfn[u] = ++dfs_clock;
    if (a[u] >= lst)
    {
        pre++;
        if (a[u] != pre + lst - 1) NO();
    }
    sort(g[u].begin(), g[u].end(), cmp);
    for (auto v : g[u]) dfs (v, dep + 1);
    suf++;
    if (a[u] < lst)
    {
        ans += dep;
        if (a[u] != suf) NO();
    }
    if (suf == lst) ed = u;
    out[u] = dfs_clock;
}

int main()
{
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) scanf ("%d", a + i);
    for (int i = 1; i < n; i++)
    {
        scanf ("%d %d", &u, &v);
        fa[v] = u;
        g[u].push_back (v);
    }
    lst = max (1, a[1] - 1);
    for (int i = 1; i <= n; i++) if (a[i] == lst) now = i;
    for (int x = now; x != 1; x = fa[x]) swap (a[x], a[fa[x]]), ans++;
    dfs (1, 0);
    if (dfn[now] > dfn[ed] || out[now] < out[ed]) NO();
    puts ("YES");
    printf ("%lld\n", ans);
    for (int i = 1; i <= n; i++) printf ("%d ", dfn[i]); puts ("");
    return 0;
}