#include<bits/stdc++.h>

using namespace std;
#define mx 300005

int n, po[mx], vis[mx], a[mx], flg = 0, pa[mx];
int cur, ed, inn, _inn, nout, in[mx], _in[mx], out[mx], en[mx];
long long rlt;
vector<int> con[mx];

bool cmp(int i, int j) {
	return a[i] < a[j];
}

void dfs(int u, int dp) {
	in[u] = ++ inn;
	if (a[u] > cur - 1) {
		_in[u] = ++ _inn + cur - 1;
	} 
	if (a[u] < cur) rlt += dp;
	for (auto v: con[u]) dfs(v, dp + 1);
	en[u] = inn;
	out[u] = ++nout;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n ; i ++) cin >> a[i], po[a[i]] = i;
	pa[1] = 0;
	for (int i = 1; i < n ; i ++) {
		int u, v;
		cin >> u >> v;
		con[u].push_back(v);
		pa[v] = u;
	}
	cur = max(1, a[1] - 1);
	
	int ip = po[cur];
    for (int u = ip; u != 1; u = pa[u]) {
        swap(po[a[u]], po[a[pa[u]]]);
        swap(a[u], a[pa[u]]);
        rlt ++;
    }
    for (int i = 1; i <= n; i ++) sort(con[i].begin(), con[i].end(), cmp);
    dfs(1, 0);
	for (int i = 1 ; i <= n; i ++) {
		if (a[i] < cur && a[i] != out[i]) {
			cout << "NO" << endl;
			return 0;
		}
		if (a[i] >= cur && a[i] != _in[i]) {
			cout << "NO" << endl;
			return 0;
		}
		if (out[i] == cur && !(in[i] >= in[ip] && en[i] <= en[ip]))  {
			cout << "NO" << endl;
			return 0;
		}
	}   
	cout << "YES" << endl;
	cout << rlt << endl;
	for (int i = 1; i <= n; i ++) cout << in[i] << " ";
	cout << endl; 
	return 0;
}

