#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 1000000007;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 300001;
void killthyself() {
    cout<<"NO\n";
    exit(0);
}
bool done[mxN];
vector<int> adj[mxN];
int minc[mxN];
int arr[mxN];
int n;
int rt;
int par[mxN];
int deg[mxN];
int bck[mxN];
int depth[mxN];
int preord[mxN];
int postord[mxN];
int postcnt = 0;
int over = 0;
int d1;
int checkcnt = 0;
void dfs(int u) {
    for(int v: adj[u]) {
        depth[v] = depth[u]+1;
        dfs(v);
    }
}
void dfsans(int u) {
    if(done[u])return;
    checkcnt++;
    if(arr[u]+1!=checkcnt) killthyself();
    if(preord[u]==INF)preord[u] = checkcnt;
    sort(adj[u].begin(), adj[u].end(), [&](int a, int b) {
        return arr[a] < arr[b];
    });
    for(int v: adj[u]) {
        dfsans(v);
    }
}
void finaldfs(int u) {
    for(int v: adj[u]) {
        finaldfs(v);
    }
    postord[u] = ++postcnt;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    owo(i, 0, n) {
        cin>>arr[i];
        arr[i]--;
        bck[arr[i]] = i;
    }
    memset(minc, INF, sizeof(minc));
    par[0] = -1;
    rt = arr[0];
    owo(i, 0, n-1) {
        int a, b;
        cin>>a>>b;
        a--; b--;
        adj[a].senpai(b);
        if(arr[b] > arr[a])minc[a] = min(minc[a], arr[b]);
        deg[a]++;
        par[b] = a;
    }
    owo(i, 0, n) {
        if(minc[i]==INF)minc[i]=-1;
    }
    dfs(0);
    bool already = 0;
    owo(_, 0, n) {
        int i = bck[_];
        if(i==0)continue;
        if(arr[par[i]] > arr[i] && minc[i] > arr[i]) {
            if(already)killthyself();
            int curr = i;
            while(minc[curr] > arr[curr]) {
                int chil = bck[minc[curr]];
                swap(bck[arr[curr]], bck[minc[curr]]);
                swap(arr[chil], arr[curr]);
                curr = chil;
                over++;
            }
            already = 1;
        }
    }
    memset(preord, INF, sizeof(preord));
    int ord = 0;
    ll ans = 0;
    owo(val, 0, n) {
        int curr = bck[val];
        if(deg[curr])break;
        done[curr] = 1;
        if(par[curr]!=-1)deg[par[curr]]--;
        ans += depth[curr];
        d1++;
        if(preord[curr]!=INF)continue;
        int nxt = par[curr];
        int cnt = 1;
        while(nxt!=-1 && preord[nxt]==INF) {
            cnt++;
            nxt = par[nxt];
        }
        preord[curr] = ord+cnt;
        nxt = par[curr];
        while(nxt!=-1 && preord[nxt]==INF) {
            cnt--;
            preord[nxt] = ord+cnt;
            nxt = par[nxt];
        }
        ord = preord[curr];
    }
    checkcnt = d1;
    dfsans(0);
    finaldfs(0);
    owo(i, 0, n) {
        if(done[i] && postord[i]!=arr[i]+1)killthyself();
    }
    cout<<"YES\n";
    cout<<ans-over<<"\n";
    owo(i, 0, n) {
        cout<<preord[i]<<" ";
    }
    return 0;
}