#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	300000

int min(int a, int b) { return a < b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
	if (X % 2 == 0)
		X++;
}

int rand_() {
	return (X *= 3) >> 1;
}

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int aa[N], pp[N], dd[N], mn[N];

void dfs1(int i, int d) {
	int o;

	dd[i] = d;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs1(j, d + 1);
	}
}

int bb[N], a_, a, b;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (mn[ii[j]] == mn[i_])
				j++;
			else if (mn[ii[j]] < mn[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

void dfs2(int i) {
	int o;

	mn[i] = aa[i];
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs2(j);
		mn[i] = min(mn[i], mn[j]);
	}
	sort(ej[i], 0, eo[i]);
}

int dfs3(int i) {
	int o;

	bb[i] = ++b;
	for (o = 0; o < eo[i]; o++) {
		int j = ej[i][o];

		if (!dfs3(j))
			return 0;
	}
	if (aa[i] < a_ && aa[i] != a++)
		return 0;
	return 1;
}

int dfs4(int i) {
	int o;

	if (aa[i] < a_)
		return 1;
	if (aa[i] != a++)
		return 0;
	for (o = 0; o < eo[i]; o++) {
		int j = ej[i][o];

		if (!dfs4(j))
			return 0;
	}
	return 1;
}

int main() {
	static int ii[N];
	int n, h, i, j, tmp;
	long long ans;

	srand_();
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]), aa[i]--;
		ii[aa[i]] = i;
	}
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		append(i, j);
		pp[j] = i;
	}
	dfs1(0, 0);
	a_ = 0, ans = 0;
	while (ii[a_] != 0)
		ans += dd[ii[a_++]];
	if (a_ > 0) {
		i = ii[--a_];
		while (i != 0) {
			if (aa[pp[i]] != a_ + dd[i]) {
				printf("NO\n");
				return 0;
			}
			tmp = aa[i], aa[i] = aa[pp[i]], aa[pp[i]] = tmp;
			i = pp[i];
		}
	}
	dfs2(0);
	if (!dfs3(0) || !dfs4(0)) {
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%lld\n", ans);
	for (i = 0; i < n; i++)
		printf("%d ", bb[i]);
	printf("\n");
	return 0;
}
