//#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define all_of(v) (v).begin(), (v).end()
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fi first
#define se second
const int MAXN = 300005;
//const LL INF = (LL) 1e9 + 8763;
//const LL MOD = (LL) 998244353;
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, a[MAXN], pos[MAXN];
int t1, t2, last, st[MAXN], ed[MAXN], dep[MAXN], pa[MAXN], mark[MAXN];
vector<int> G[MAXN];

void dfs0(int v, int d) {
	dep[v] = d;
	st[v] = ++t1;
	for (int to : G[v]) {
		dfs0(to, d + 1);
	}
	ed[v] = ++t2;
}

int is_anc(int p, int v) {
	return st[p] <= st[v] && ed[v] <= ed[p];
}

void nope() {
	cout << "NO\n";
	exit(EXIT_SUCCESS);
}

void yup() {
	LL ans = 0;
	for (int i = 1; i <= last; i++) {
		ans += dep[pos[i]];
	}
	cout << "YES\n";
	cout << ans << '\n';
	for (int i = 1; i <= n; i++) {
		cout << st[i] << " \n"[i == n];
	}
	exit(EXIT_SUCCESS);
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}
	pa[1] = 1;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		pa[v] = u;
	}
	
	// prep
	for (int i = 1; i <= n; i++) {
		sort(G[i].begin(), G[i].end(), [&] (int x, int y) {
			return a[x] < a[y];
		});
	}
	dfs0(1, 0);

	vector<int> ords({-1}), ordt({-1});
	for (int i = 1; i <= n; i++) {
		ords.push_back(i);
		ordt.push_back(i);
	}
	sort(all_of(ords), [&] (int x, int y) {
		return st[x] < st[y];
	});
	sort(all_of(ordt), [&] (int x, int y) {
		return ed[x] < ed[y];
	});
	
	last = n + 1;
	for (int i = 1; i <= n; i++) {
		if (a[ordt[i]] != i) {
			last = i;
			break;
		}
	}
	if (last == n + 1) {
		yup();
	}
	if (!is_anc(pos[last], ordt[last])) {
		nope();
	}
	
	// phase 1, mark the subtreeeee
	for (int i = 1; i <= last; i++) {
		int v = pos[i];
		while (!mark[v] && v != 1) {
			mark[v] = 1;
			v = pa[v];
		}
		mark[v] = 1;
	}
	for (int i = 1; i <= n; i++) {
		if (!mark[i] && a[i] != st[i]) {
			nope();
		}
	}
	
	// phase 2, check the pathhhhh
	int cur = ordt[last];
	vector<int> path;
	while (1) {
		if (a[cur] != last) {
			path.push_back(a[cur]);
		}
		if (cur == 1) {
			break;
		}
		cur = pa[cur];
	}
	for (int i = 1; i < path.size(); i++) {
		if (path[i] > path[i - 1]) {
			nope();
		}
	}
	
	// ok!
	yup();
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int tc = 1;
//	cin >> tc;
	for (int i = 1; i <= tc; i++) {
		solve();
	}
	return 0;
}