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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

int lg(ll n) {
    assert(n > 0);
    int ans = -1;
    while (n) {
        ans++;
        n >>= 1;
    }
    return ans;
}

void leave() {
    cout << "NO" << '\n';
    exit(0);
}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N), pos(N);
    vector<vector<int>> adj(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
        pos[A[i]] = i;
    }
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    vector<int> dep(N), par(N);
    vector<int> pre_ord, post_ord;
    vector<vector<int>> children(N);
    function<void(int, int)> dfs = [&](int cur, int fa) {
        pre_ord.push_back(cur);
        par[cur] = fa;
        for (int nxt : adj[cur]) {
            if (nxt != fa) {
                dep[nxt] = dep[cur] + 1;
                children[cur].push_back(nxt);
            }
        }
        sort(children[cur].begin(), children[cur].end(),
             [&](const int &i, const int &j) { return A[i] < A[j]; });
        for (int child : children[cur]) {
            dfs(child, cur);
        }
        post_ord.push_back(cur);
    };
    dep[0] = 0;
    dfs(0, -1);
    vector<int> ans(N, -1);
    ll T = 0;
    for (int i = 0; i < N; i++) {
        if (pos[i] == post_ord[i]) {
            T += dep[post_ord[i]];
        } else {
            int cur = pos[i];
            int target = post_ord[i];
            while (target >= 0) {
                if (target == cur) break;
                target = par[target];
            }
            if (target == -1) {
                leave();
            }
            while (cur != 0) {
                pos[A[par[cur]]] = cur;
                pos[A[cur]] = par[cur];
                swap(A[par[cur]], A[cur]);
                cur = par[cur];
                T++;
            }
            for (int j = 0; j < i; j++) {
                if (pos[j] != post_ord[j]) {
                    leave();
                }
            }
            vector<int> pre_ord2;
            function<void(int, int)> dfs2 = [&](int cur, int fa) {
                pre_ord2.push_back(cur);
                for (int nxt : children[cur]) {
                    if (nxt == fa || A[nxt] < i) continue;
                    dfs2(nxt, cur);
                }
            };
            dfs2(0, -1);
            assert((int)pre_ord2.size() == N - i);
            /*for (int j = 0; j < N - i; j++) {
                cout << pre_ord2[j] << " \n"[j == N - i - 1];
            }*/
            for (int j = 0; j < N - i; j++) {
                if (A[pre_ord2[j]] != j + i) {
                    leave();
                }
            }
            break;
        }
    }
    for (int i = 0; i < N; i++) {
        ans[pre_ord[i]] = i;
    }
    cout << "YES\n" << T << '\n';
    for (int i = 0; i < N; i++) {
        cout << ans[i] + 1 << " \n"[i == N - 1];
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
