#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 300005;
int n, err = 0;
int b[N];
int dep[N], fa[N], a[N], In[N], Out[N], arr[N], vis[N];
vector<int> G[N];
int timo = 0, timi = 0, tim;
void add_edge(int x, int y)
{
	G[x].push_back(y);
}

void dfs(int x)
{
	In[++timi] = x; arr[x] = timi;
	sort(G[x].begin(), G[x].end(), [&](int p, int q){return a[p] < a[q];});
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		fa[to] = x;
		dep[to] = dep[x] + 1;
		dfs(to);
	}
	Out[++timo] = x;
}

void init()
{
	read(n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	for (int i = 1, u, v; i < n; ++i)
	{
		read(u); read(v);
		add_edge(u, v);
	}
	dfs(1);
}

void run(int x)
{
	++tim;
	if (a[x] != tim) err = 1;
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		if (vis[to]) continue;
		run(to);
	}
}

bool is_anc(int x, int y)
{
	while (y)
	{
		if (x == y) return 1;
		y = fa[y];
	}
	return 0;
}

void solve()
{
	ll ans = 0;
	int r = a[1];
	for (int i = 1; i <= r - 2; ++i)
	{
		if (a[Out[i]] ^ i)
		{
			printf("NO\n");
			return;
		}
		ans += dep[Out[i]];
	}
	int pos = 0;
	for (int i = 1; i <= n; ++i) if (a[i] == r - 1) pos = i;
	if (r && !is_anc(pos, Out[r - 1]))
	{
		printf("NO\n");
		return;
	}
	for (int i = 1; i <= r - 2; ++i) vis[Out[i]] = 1;
	while (pos > 1)
	{
		swap(a[pos], a[fa[pos]]);
		pos = fa[pos];
		++ans;
	}
	tim = a[1] - 1; run(1);
	if (err)
	{
		printf("NO\n");
		return;
	}
	printf("YES\n%lld\n", ans);
	for (int i = 1; i <= n; ++i) printf("%d%c", arr[i], " \n"[i == n]);
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}
