#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
const ll MAXN = 300011;

struct Edge {ll v, nxt;} e[MAXN];

ll n, now, ans;
ll head[MAXN], cnt;
ll w[MAXN], fa[MAXN];
ll dfn[MAXN], dep[MAXN], tot;
ll b[MAXN], tot2, c[MAXN], tot1;

bool flag;

inline ll read() {
	ll X = 0, F = 1; char C = getchar();
	while(C < '0' || C > '9') {if(C == '-')F=-1; C = getchar();}
	while(C >= '0' && C <= '9') {X = X*10+C-'0'; C = getchar();}
	return X * F;
}

inline void add_Edge(ll u, ll v) {
	e[++cnt] = (Edge) {v, head[u]}; head[u] = cnt;
}

inline bool cmp(int x, int y) {return w[x] > w[y];}

void dfs(ll u) {
	dfn[u] = ++tot; dep[u] = dep[fa[u]] + 1;
	if(w[u] < now) ans += dep[u] - 1;
	else b[u] = tot2++, b[u] += now;
	vector<int> vec;
	for(int i = head[u]; i; i = e[i].nxt) vec.push_back(e[i].v);
	sort(vec.begin(), vec.end(), cmp);
	for(int i = vec.size() - 1; i >= 0; --i) dfs(vec[i]);
	c[u] = ++tot1;
}

int main() {
	n = read();
	for(register ll i = 1; i <= n; ++i) w[i] = read();
	for(register ll i = 1, u, v; i < n; ++i) {
		u = read(); v = read();
		add_Edge(u, v);
		fa[v] = u;
	}
	now = w[1]; ll u;
	if(now != 1) {
		--now;
		for(ll i = 1; i <= n; ++i) if(w[i] == now) {u = i; break;}
		while(u != 1) {
			if(w[fa[u]] < w[u]) {flag = 1; break;}
			swap(w[fa[u]], w[u]);
			for(register ll i = head[fa[u]]; i; i = e[i].nxt)
				if(w[e[i].v] > w[fa[u]] && w[e[i].v] < w[u]) {flag = 1; break;}
			u = fa[u]; ++ans;
		}
	}
	dfs(1);
	for(register int i = 1; i <= n && !flag; ++i) if(w[i] < now && w[i] != c[i]) {flag = 1; break;}
	for(register int i = 1; i <= n && !flag; ++i) if(w[i] >= now && w[i] != b[i]) {flag = 1; break;}
	if(flag) puts("NO");
	else {
		puts("YES");
		printf("%lld\n", ans);
		for(register int i = 1; i <= n; ++i) printf("%lld ", dfn[i]);
		puts("");
	}
	return 0;
}