#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 3e5 + 5;
vector<int> G[N], G0[N];
long long day;
int cur, n, pv, pt, a[N], fa[N], dep[N];
int prv[N], pst[N], np[N], bp[N], ep[N];
void Build(int u) {
	for(int v : G0[u]) {
		if(v == fa[u]) continue;
		fa[v] = u;
		dep[v] = dep[u] + 1;
		Build(v);
		G[u].pb(v); 
	}
	sort(G[u].begin(), G[u].end(), [](int x, int y){ return a[x] < a[y]; });
}
void Dfs1(int u) {
	for(int v : G[u]) Dfs1(v);
	pst[u] = ++pt;
	ep[pt] = u;
}
bool Find(int u, int v) {
	if(u == v) return true;
	if(u == 1) return false; 
	return Find(fa[u], v);
}
void Back(int u) {
	if(u == 1) return;
	swap(a[u], a[fa[u]]);
	day++;
	Back(fa[u]); 
}
void Dfs2(int u) {
	if(a[u] < cur) return;
	prv[u] = pv;
	bp[pv++] = u;
	for(int v : G[u]) Dfs2(v);
}
void Dfs3(int u) {
	prv[u] = ++pv;
	for(int v : G[u]) Dfs3(v);
}
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		np[a[i]] = i; 
	}
	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		G0[u].pb(v);
		G0[v].pb(u);
	}
	Build(1);
	Dfs1(1);
	if(a[1] == 1) {
		Dfs3(1);
		for(int i = 1; i <= n; i++) {
			if(prv[i] != a[i]) {
				cout << "NO\n";
				return 0;
			}
		}
		cout << "YES\n0\n";
		for(int i = 1; i <= n; i++) cout << prv[i] << ' ';
		return 0; 
	}
	cur = a[1] - 1;
	if(!Find(ep[cur], np[cur])) {
		cout << "NO\n";
		return 0;
	}
	Back(np[cur]);
	for(int i = 1; i <= n; i++) np[a[i]] = i;
	for(int i = 1; i < cur; i++) {
		if(np[i] != ep[i]) {
			cout << "NO\n";
			return 0;
		}
	}
	pv = cur;
	Dfs2(1);
	for(int i = cur; i <= n; i++) {
		if(np[i] != bp[i]) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	for(int i = 1; i < cur; i++) day += dep[np[i]];
	cout << day << endl;
	pv = 0;
	Dfs3(1);
	for(int i = 1; i <= n; i++) cout << prv[i] << ' ';
	return 0;
}