/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

/****** Template of some basic operations *****/
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
/**********************************************/;

bool clean(uint32 u, vector<uint32> *adj, uint32 *a, uint64& days, uint32 x) {
    if (a[u] == x) {
        return true;
    }

    for (uint32 v : adj[u]) {
        if (a[v] >= x) {
            bool res = clean(v, adj, a, days, x);
            if (res) {
                swap(a[u], a[v]);
                days++;
            }
            return res;
        }
    }
    return false;
}

bool postorder(uint32 u, vector<uint32> *adj, uint32 *a, uint32& cnt, uint32 x) {
    bool res;
    for (uint32 v : adj[u]) {
        res = postorder(v, adj, a, cnt, x);
        if (!res) return res;
    }
    // printf("Postorder check %d(u=%d) against %d\n", a[u], u, cnt);
    if (cnt + 1 < x && a[u] == cnt + 1) {
        cnt++; return true;
    } else return cnt + 1 >= x && a[u] >= x;
}

bool preorder(uint32 u, vector<uint32> *adj, uint32 *a, uint32& cnt, uint32 x) {
    // printf("Preorder check %d(u=%d) against %d\n", a[u], u, cnt);
    if (a[u] >= x && a[u] != ++cnt) return false;
    bool res;
    for (uint32 v : adj[u]) {
        res = preorder(v, adj, a, cnt, x);
        if (!res) return res;
    }
    return true;
}

void countDays(uint32 u, vector<uint32> *adj, uint32 *a, uint64& days, uint32 x, uint32 h) {
    for (uint32 v : adj[u]) {
        countDays(v, adj, a, days, x, h+1);
    }
    if (a[u] < x) {
        days += h;
    }
    // printf("Count days=%d h=%d\n", days, h);
}

void dfs(uint32 u, vector<uint32> *adj, uint32 *a, uint32& order) {
    order++;
    a[u] = order;
    for (uint32 v : adj[u]) {
        dfs(v, adj, a, order);
    }
}

struct Comp {
    uint32 *a;

    bool operator() (uint32 i, uint32 j) {
        return a[i] < a[j];
    }
};

void solve() {
    uint32 n; SCLD(n);
    uint32 a[n];
    REP(i, n) SCLD(a[i]);

    uint32 u, v;
    vector<uint32> adj[n];
    REP(i, n-1) {
        SCLD(u); SCLD(v);
        adj[--u].PB(--v);
    }
    Comp c;
    c.a = a;
    REP(i, n) sort(all(adj[i]), c);

    uint32 x = a[0] - 1;
    uint64 days = 0;
    bool res = clean(0, adj, a, days, x);
    // printf("Clean: %d\n", res);
    // REP(i, n) cout << a[i] << " ";
    // cout << endl;
    if (!res) {
        cout << "NO" << endl;
        return;
    }

    uint32 cnt = 0;
    bool post = postorder(0, adj, a, cnt, x);
    bool pre = preorder(0, adj, a, cnt, x);
    // printf("Post: %d, Pre: %d\n", post, pre);
    if (!post || !pre) {
        cout << "NO" << endl;
        return;
    } else {
        cout << "YES" << endl;
    }

    // printf("Days before: %d\n", days);
    countDays(0, adj, a, days, x, 0);
    cout << days << endl;

    uint32 order = 0;
    uint32 new_a[n];
    dfs(0, adj, new_a, order);
    REP(i, n) cout << new_a[i] << " ";
    cout << endl;
}

int main() {
    int t = 1; 
    // SCD(t);
    while (t--) {
        solve();
    }
}